package org.bigdata.framework.admin.web.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.io.FileUtils;
import org.bigdata.framework.admin.web.util.DBUtils;
import org.bigdata.framework.admin.web.util.DateUtils;
import org.bigdata.framework.admin.web.util.FileDownloadUtil;
import org.bigdata.framework.admin.web.util.TreeJsion;
import org.bigdata.framework.admin.web.util.ValidateSQL;
import org.bigdata.framework.core.model.Classes;
import org.bigdata.framework.core.model.CommonDataProperty;
import org.bigdata.framework.core.model.CommonObjectProperty;
import org.bigdata.framework.core.model.DataExport;
import org.bigdata.framework.core.model.DataImport;
import org.bigdata.framework.core.model.DataProperty;
import org.bigdata.framework.core.model.DataSource;
import org.bigdata.framework.core.model.DataType;
import org.bigdata.framework.core.model.Department;
import org.bigdata.framework.core.model.Dict;
import org.bigdata.framework.core.model.DictItem;
import org.bigdata.framework.core.model.Log;
import org.bigdata.framework.core.model.Menu;
import org.bigdata.framework.core.model.ObjectProperty;
import org.bigdata.framework.core.model.Permission;
import org.bigdata.framework.core.model.PermissionClasses;
import org.bigdata.framework.core.model.User;
import org.bigdata.framework.core.model.UserRole;
import org.bigdata.framework.core.model.Workflow;
import org.bigdata.framework.core.model.WorkflowNode;
import org.bigdata.framework.core.protocol.IBaseService;
import org.bigdata.framework.core.protocol.IDataHandlingService;
import org.bigdata.framework.core.protocol.IDynamicService;
import org.bigdata.framework.core.protocol.IPayService;
import org.bigdata.framework.core.protocol.IPublicService;
import org.bigdata.framework.core.protocol.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.xxl.conf.core.XxlConfClient;

@Controller
public class KnowledgeClassController extends BaseContoroller {

	@Autowired
	private IBaseService baseService;

	@Autowired
	private IPublicService publicService;
	@Autowired
	private IDynamicService dynamicService;
	@Autowired
	private ISearchService searchService;
	@Autowired
	private IPayService payService;
	@Autowired
	private IDataHandlingService dataHandlingService;

	// 公共日常记录
	public void Log(Integer createUserId, String logType, String classesId,
			String dataId, String logText, Integer logStatus) throws Exception {
		// 获得本机IP
		InetAddress addr = InetAddress.getLocalHost();
		String createIpAddress = addr.getHostAddress();
		// 获得时间
		String createTime = DateUtils.getDateTime();

		Log log = new Log();
		log.setCreateTime(createTime);
		log.setCreateUserId(createUserId);
		log.setCreateIpAddress(createIpAddress);
		log.setLogType(logType);
		log.setLogText(logText);
		log.setLogStatus(logStatus);

		if (classesId != null) {
			log.setClassesId(classesId);
		}
		if (dataId != null) {
			log.setDataId(dataId);
		}
		baseService.saveLog(log);
	}

	/*
	 * 数据类型管理
	 */

	// 跳转数据类型查询页面。
	@RequestMapping("user-menu-categoryList.html")
	public String toKnowledgeCategorylist(HttpServletResponse response)
			throws IOException {

		return "/modules/knowledgedata/knowledge_data_category_list";
	}

	// 跳转数据类型添加页面。
	@RequestMapping("knowledge-data-category-from.html")
	public String toKnowledgeCategoryfrom(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "/modules/knowledgedata/knowledge_data_category_from";
	}

	// 查询所有的数据类型，提供下拉选择。
	@RequestMapping("KnowledgeListall")
	public void toKnowledgeListall(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<DataType> DataType1 = publicService.getDataType();
		String result = formatToJson(DataType1);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 修改数据类型。
	@RequestMapping("Knowledgeedit")
	public void toKnowledgeCategoryedit(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataType DataType1 = publicService.findDataType(Integer.parseInt(id));
		String result = formatToJson(DataType1);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 删除数据类型。
	@RequestMapping("Knowledgedel")
	public void toKnowledgeCategorydel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataType DataType1 = new DataType();
		DataType1.setId(Integer.parseInt(id));
		baseService.deleteDataType(DataType1);
		String result = "{\"result\":" + "\"ok\"}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 保存数据类型。
	@RequestMapping("Knowledgesave")
	public void toKnowledgeCategorydatasave(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String solrType = request.getParameter("solrType");
		String fieldType = request.getParameter("fieldType");
		// Integer sort = (request.getParameter("sort"));
		Integer sort = Integer.parseInt(request.getParameter("sort"));
		DataType DataType1 = new DataType();
		DataType1.setNameEn(nameEn);
		DataType1.setNameZh(nameZh);
		DataType1.setSort(sort);
		DataType1.setFieldType(fieldType);
		DataType1.setSolrType(solrType);
		DataType DataType2 = new DataType();
		if (!id.equals("0")) {
			DataType1.setId(Integer.parseInt(id));
			DataType2 = baseService.editDataType(DataType1);
		} else {
			// DataType1.setId(null);
			DataType2 = baseService.saveDataType(DataType1);
		}
		String result = formatToJson(DataType2);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 查询所有的数据类型，提供搜索查询。
	@RequestMapping("KnowledgeList")
	@ResponseBody
	public void toKnowledgeCategorydataList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = Integer.parseInt(request
				.getParameter("pageNumber"));
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");

		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if(text !=null && !"".equals(text)){
			queryParams.put("%,"+queryParam, text);
		}
		List<DataType> list = publicService.getDataType(queryParams, pageSize,
				pageNumber);
		long count = publicService.getDataTypeCount(queryParams);
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}

	/*
	 * 公共基础字段的管理
	 */

	// 跳转公共基础字段列表页面。
	@RequestMapping("show-Common-DataList.html")
	public String toKnowledgeCommonList() throws IOException {

		return "/modules/knowledgedata/knowledge_Common_DataList";
	}

	// 跳转公共基础字段添加页面。
	@RequestMapping("knowledge-Common-DataFrom.html")
	public String toKnowledgeCommonDatafrom(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "/modules/knowledgedata/knowledge_Common_DataFrom";
	} // 显示列表
		// 查询所有的公共基础字段，提供搜索查询。

	@RequestMapping("KnowledgeCommonDataList")
	@ResponseBody
	public void toKnowledgeCommonDataList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = Integer.parseInt(request
				.getParameter("pageNumber"));
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if(text != null && !"".equals(text)){
			queryParams.put("%,"+queryParam, text);
		}
		List<CommonDataProperty> list = publicService.getCommonDataProperty(
				queryParams, pageSize, pageNumber);
		long count = publicService.getCommonDataPropertyCount(queryParams);
		List<DataType> dataType =publicService.getDataType();
		List<Dict> dict =publicService.getDict();
		/*for (int i = 0; i < list.size(); i++) {
			CommonDataProperty aCommonDataProperty = list.get(i);
			DataType aDataType = null;
			if (aCommonDataProperty.getDataTypeId() != 0) {
				aDataType = publicService.findDataType(aCommonDataProperty.getDataTypeId());
			}
			//list.get(i).setDataType(aDataType);

			Dict aDict = null;
			if (aCommonDataProperty.getDictId() != 0) {
				aDict = publicService.findDict(aCommonDataProperty.getDictId());
			}
			//list.get(i).setDict(aDict);

		}*/

		String result = formatToJson(list);
		String rdataType = formatToJson(dataType);
		String rdict = formatToJson(dict);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result + ",");
		sb.append("\"rdataType\":" + rdataType + ",");
		sb.append("\"rdict\":" + rdict);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	} // 新增和修改
		// 保存所有的公共基础字段值。

	@RequestMapping("KnowledgeCommonDatasave")
	public void toKnowledgeCommonDatasavedata(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String field = request.getParameter("field");
		String dataTypeid = request.getParameter("dataType");
		String dictid = request.getParameter("dict");
		Integer fieldLength = Integer.parseInt(request.getParameter("fieldLength"));
		String required = request.getParameter("required");
		String multiValued = request.getParameter("multiValued");
		String stored = request.getParameter("stored");
		String indexed = request.getParameter("indexed");
		String termVectors = request.getParameter("termVectors");
		String faceted = request.getParameter("faceted");
		String generalSearchField = request.getParameter("generalSearchField");
		String advancedSearchField = request.getParameter("advancedSearchField");
		String searchWithinResultsField = request.getParameter("searchWithinResultsField");
		String highlightingField = request.getParameter("highlightingField");
		String productGeneralSearchField = request.getParameter("productGeneralSearchField");
		String productAdvancedSearchField = request.getParameter("productAdvancedSearchField");
		Integer sort = Integer.parseInt(request.getParameter("sort"));
		User logUser = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		CommonDataProperty CommonDataProperty1 = new CommonDataProperty();
		CommonDataProperty1.setDataTypeId(Integer.parseInt(dataTypeid));
		CommonDataProperty1.setDictId(Integer.parseInt(dictid));
		CommonDataProperty1.setFieldLength(fieldLength);
		CommonDataProperty1.setNameEn(nameEn);
		CommonDataProperty1.setNameZh(nameZh);
		CommonDataProperty1.setField(field);
		CommonDataProperty1.setIndexed(indexed);
		CommonDataProperty1.setMultiValued(multiValued);
		CommonDataProperty1.setRequired(required);
		CommonDataProperty1.setStored(stored);
		CommonDataProperty1.setTermVectors(termVectors);
		CommonDataProperty1.setSort(sort);
		CommonDataProperty1.setHighlightingField(highlightingField);
		CommonDataProperty1.setFaceted(faceted);
		CommonDataProperty1.setGeneralSearchField(generalSearchField);
		CommonDataProperty1.setAdvancedSearchField(advancedSearchField);
		CommonDataProperty1.setSearchWithinResultsField(searchWithinResultsField);
		CommonDataProperty1.setProductGeneralSearchField(productGeneralSearchField);
		CommonDataProperty1.setProductAdvancedSearchField(productAdvancedSearchField);
		CommonDataProperty DataType2 = new CommonDataProperty();
		if (!id.equals("0")) {
			CommonDataProperty1.setId(Integer.parseInt(id));
			int logTime = 0;
			try {
				DataType2 = baseService.editCommonDataProperty(CommonDataProperty1);
			} catch (Exception e) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【修改】公共基础字段【" + nameZh
						+ "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【修改】公共基础字段【" + nameZh
						+ "】成功！", 0);
			}

		} else {
			int logTime = 0;
			try {
				DataType2 = baseService.saveCommonDataProperty(CommonDataProperty1);
			} catch (Exception e) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【新增】公共基础字段【" + nameZh
						+ "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【新增】公共基础字段【" + nameZh
						+ "】成功！", 0);
			}

		}
		String result = formatToJson(DataType2);
		super.pringWriterToPage(result.toString(), "application/json", response);
	} // 去查询修改
		// 修改公共基础字段的值

	@RequestMapping("KnowledgeCommonDataedit")
	public void toKnowledgeCommonDataedit(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		CommonDataProperty CommonDataProperty1 = publicService.findCommonDataProperty(Integer.parseInt(id));
		List<DataType> dataType =publicService.getDataType();
		List<Dict> dict = publicService.getDict();
		/*if (CommonDataProperty1.getDataTypeId() != 0) {
			aDataType = publicService.findDataType(CommonDataProperty1.getDataTypeId());
		}
		//CommonDataProperty1.setDataType(aDataType);
		Dict aDict = null;
		if (CommonDataProperty1.getDictId() != 0) {
			aDict = publicService.findDict(CommonDataProperty1.getDictId());
		}*/
		//CommonDataProperty1.setDict(aDict);
		String result = formatToJson(CommonDataProperty1);
		super.pringWriterToPage(result.toString(), "application/json", response);

	} // 删除
		// 删除公共基础字段的值

	@RequestMapping("KnowledgeCommonDatadel")
	public void toKnowledgeCommonDatadel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		CommonDataProperty commonDataProperty1 = new CommonDataProperty();
		commonDataProperty1.setId(Integer.parseInt(id));
		List<Classes> listClasses = publicService.getClasses();
		boolean falg = false;
		for (Classes classes : listClasses) {
			List<DataProperty> aDataPropertyList = publicService
					.getDataProperty(classes);
			for (int i = 0; i < aDataPropertyList.size(); i++) {
				if (aDataPropertyList.get(i).getCommonDataPropertyId() == Integer
						.parseInt(id)) {
					falg = true;
				}
			}
		}
		String result = "";
		if (falg) {
			result = "{\"result\":" + "\"error\"}";
		} else {
			int logTime = 0;
			User logUser = publicService.findUser((Integer) request
					.getSession().getAttribute("userid"));
			CommonDataProperty commonDataProperty = publicService
					.findCommonDataProperty(Integer.parseInt(id));
			try {
				baseService.deleteCommonDataProperty(commonDataProperty1);
			} catch (Exception e) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【删除】公共基础字段【"
						+ commonDataProperty.getNameZh() + "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【删除】公共基础字段【"
						+ commonDataProperty.getNameZh() + "】成功！", 0);
			}

			result = "{\"result\":" + "\"ok\"}";
		}

		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 查询所有的公共字段，提供下拉选择。
	@RequestMapping("KnowledgeCommonDataPropertyListall")
	public void toKnowledgeCommonDataPropertyListall(
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<CommonDataProperty> list = publicService.getCommonDataProperty();
		for (int i = 0; i < list.size(); i++) {
			CommonDataProperty aCommonDataProperty = new CommonDataProperty();
			aCommonDataProperty = list.get(i);
			DataType aDataType = new DataType();
			if (aCommonDataProperty.getDataTypeId() != 0) {
				aDataType = publicService.findDataType(aCommonDataProperty
						.getDataTypeId());
				//list.get(i).setDataType(aDataType);
			} else {
				//list.get(i).setDataType(aDataType);
			}
			Dict aDict = new Dict();
			if (aCommonDataProperty.getDictId() != 0 && aCommonDataProperty.getDictId() != null) {
				aDict = publicService.findDict(aCommonDataProperty.getDictId());
				//list.get(i).setDict(aDict);
			} else {
				//list.get(i).setDict(aDict);
			}
		}
		String result = formatToJson(list);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	@RequestMapping("listAllCommonDataCnAndEnName")
	public void listAllCommonDataCnAndEnName(
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<CommonDataProperty> list = publicService.getCommonDataProperty();
		super.pringWriterToPage(formatToJson(list), "application/json", response);

	}
	// 验证CommonDataProperty的NameEn是否重名
	@RequestMapping("KnowledgeCommonDataPropertyProving")
	public void toKnowledgeCommonDataPropertyProving(
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String name = request.getParameter("name");
		// System.out.println(name);
		List<CommonDataProperty> list1 = publicService.getCommonDataProperty();
		int falg = 1;
		for (int i = 0; i < list1.size(); i++) {
			if (name.equals(list1.get(i).getNameEn())) {
				falg = 2;
			}
		}
		boolean falg1 = ValidateSQL.Proving(name);
		if (!falg1) {
			falg = 3;
		}
		boolean falg2 = ValidateSQL.Provname(name);
		if (!falg2) {
			falg = 4;
		}
		String result = "{\"result\":" + falg + "}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	/*
	 * 公共对象字段的管理
	 */

	// 跳转公共对象字段列表页面。
	@RequestMapping("show-Common-ObjectList.html")
	public String toKnowledgeCommonObjectList() throws IOException {

		return "/modules/knowledgedata/knowledge_Common_ObjectList";
	}

	// 跳转公共对象字段添加页面。
	@RequestMapping("knowledge-Common-ObjectFrom.html")
	public String toKnowledgeCommonObjectfrom(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "/modules/knowledgedata/knowledge_Common_ObjectFrom";
	}// 显示列表
		// 查询所有的公共对象字段，提供搜索查询。

	@RequestMapping("KnowledgeCommonObjectList")
	@ResponseBody
	public void toKnowledgeCommonObjectList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = Integer.parseInt(request
				.getParameter("pageNumber"));
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if(text != null && !"".equals(text)){
			queryParams.put("%,"+queryParam, text);
		}
		List<CommonObjectProperty> list = publicService
				.getCommonObjectProperty(queryParams, pageSize, pageNumber);
		long count = publicService.getCommonObjectPropertyCount(queryParams);

		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}

	// 查询所有的对象类型，提供下拉选择。
	@RequestMapping("KnowledgeCommonObjectall")
	public void toKnowledgeCommonObjectListall(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<CommonObjectProperty> DataType1 = publicService
				.getCommonObjectProperty();
		String result = formatToJson(DataType1);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 保存所有的公共对象字段值。

	@RequestMapping("KnowledgeCommonObjectsave")
	public void toKnowledgeCommonObjectsave(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String field = request.getParameter("field");
		String required = request.getParameter("required");
		String multiValued = request.getParameter("multiValued");
		String stored = request.getParameter("stored");
		String indexed = request.getParameter("indexed");
		String termVectors = request.getParameter("termVectors");
		Integer sort = Integer.parseInt(request.getParameter("sort"));
		User logUser = publicService.findUser((Integer) request.getSession().getAttribute("userid"));

		CommonObjectProperty CommonObjectProperty1 = new CommonObjectProperty();
		CommonObjectProperty1.setNameEn(nameEn);
		CommonObjectProperty1.setNameZh(nameZh);
		CommonObjectProperty1.setField(field);
		CommonObjectProperty1.setIndexed(indexed);
		CommonObjectProperty1.setMultiValued(multiValued);
		CommonObjectProperty1.setRequired(required);
		CommonObjectProperty1.setStored(stored);
		CommonObjectProperty1.setTermVectors(termVectors);
		CommonObjectProperty1.setSort(sort);
		CommonObjectProperty DataType2 = new CommonObjectProperty();
		if (!id.equals("0")) {
			CommonObjectProperty1.setId(Integer.parseInt(id));
			int logTime = 0;
			try {
				DataType2 = baseService
						.editCommonObjectProperty(CommonObjectProperty1);
			} catch (Exception e) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【修改】公共关联字段【" + nameZh
						+ "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【修改】字公共关联字段【" + nameZh
						+ "】成功！", 0);
			}

		} else {
			int logTime = 0;
			try {
				DataType2 = baseService
						.saveCommonObjectProperty(CommonObjectProperty1);
			} catch (Exception e) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【新增】公共关联字段【" + nameZh
						+ "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【新增】字公共关联字段【" + nameZh
						+ "】成功！", 0);
			}

		}
		String result = formatToJson(DataType2);
		super.pringWriterToPage(result.toString(), "application/json", response);
	} // 去查询修改
		// 修改公共对象字段的值

	@RequestMapping("KnowledgeCommonObjectedit")
	public void toKnowledgeCommonObjectedit(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		CommonObjectProperty CommonObjectProperty1 = publicService
				.findCommonObjectProperty(Integer.parseInt(id));
		String result = formatToJson(CommonObjectProperty1);
		super.pringWriterToPage(result.toString(), "application/json", response);

	} // 删除
		// 删除公共对象字段的值

	@RequestMapping("KnowledgeCommonObjcetdel")
	public void toKnowledgeCommonObjectdel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		CommonObjectProperty CommonObjectProperty1 = new CommonObjectProperty();
		CommonObjectProperty1.setId(Integer.parseInt(id));
		List<Classes> listClasses = publicService.getClasses();
		boolean falg = false;
		for (Classes classes : listClasses) {
			List<ObjectProperty> aObjectPropertyList = publicService
					.getObjectProperty(classes);
			for (int i = 0; i < aObjectPropertyList.size(); i++) {
				if (aObjectPropertyList.get(i).getCommonObjectPropertyId() == Integer
						.parseInt(id)) {
					falg = true;
				}
			}
		}
		String result = "";
		if (falg) {
			result = "{\"result\":" + "\"error\"}";
		} else {
			int logTime = 0;
			User logUser = publicService.findUser((Integer) request
					.getSession().getAttribute("userid"));
			CommonObjectProperty commonObjectProperty = publicService
					.findCommonObjectProperty(Integer.parseInt(id));
			try {
				baseService.deleteCommonObjectProperty(CommonObjectProperty1);
			} catch (Exception e) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【删除】公共关联字段【"
						+ commonObjectProperty.getNameZh() + "】失败！请检查数据是否正确！",
						1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【删除】字公共关联字段【"
						+ commonObjectProperty.getNameZh() + "】成功！", 0);
			}

			result = "{\"result\":" + "\"ok\"}";
		}

		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 验证CommonObjectProperty的NameEn是否重名
	@RequestMapping("KnowledgeCommonObjectPropertyProving")
	public void toKnowledgeCommonObjectProving(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String name = request.getParameter("name");
		// System.out.println(name);
		List<CommonObjectProperty> list1 = publicService
				.getCommonObjectProperty();
		int falg = 1;
		for (int i = 0; i < list1.size(); i++) {
			if (name.equals(list1.get(i).getNameEn())) {
				falg = 2;
			}
		}
		boolean falg1 = ValidateSQL.Proving(name);
		if (!falg1) {
			falg = 3;
		}
		boolean falg2 = ValidateSQL.Provname(name);
		if (!falg2) {
			falg = 4;
		}
		String result = "{\"result\":" + falg + "}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	/*
	 * Classes的管理
	 */

	// 跳转Classes的管理页面。
	@RequestMapping("knowledge-edit-class-listl.html")
	public String toKnowledgeEditClassList() {

		return "/modules/knowledgedata/knowledge_DataProperty_class_from";
	}

	// 跳转Domain选择
	@RequestMapping("knowledge-Domain-domain-zTree.html")
	public String toKnowledgeDomainDomainzTree() {

		return "/modules/knowledgedata/knowledge_Domain_domain_zTree";
	}

	// 跳转Classes选择
	@RequestMapping("knowledge-Classes-class-zTree.html")
	public String toKnowledgeClassclasszTree() {

		return "/modules/knowledgedata/knowledge_Classes_class_zTree";
	}

	// 跳转Classes添加表单
	@RequestMapping("knowledge-Classes-class-from.html")
	public String toKnowledgeClassesclassEdit() {

		return "/modules/knowledgedata/knowledge_Classes_class_from";
	}
	// 跳转数推荐类
	@RequestMapping("knowledge-Classes-recommendClass-zTree.html")
	public String toknowledgeClassesRecommendClassZTree(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "/modules/knowledgedata/knowledge_Classes_recommendClass_zTree";
	}
	// 跳转资源库标识
	@RequestMapping("knowledge-Classes-db-zTree.html")
	public String toknowledgeClassesdbzTree(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "/modules/knowledgedata/knowledge_Classes_db_zTree";
	}
	
	// 跳转数推荐类
	@RequestMapping("knowledge-Classes-class-button.html")
	public String toknowledgeClassesClassButton(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "/modules/knowledgedata/knowledge_Classes_class_button";
	}
	// 查询所有列表的Classes,条件查询
	@RequestMapping("KnowledgeclassListallcell")
	public void toKnowledgeclassListallcell(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = Integer.parseInt(request
				.getParameter("pageNumber"));
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");

		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if(text != null && !"".equals(text)){
			queryParams.put("=,"+queryParam, text);
		}
		List<Classes> list = publicService.getClasses(queryParams, pageSize,
				pageNumber);
		long count = publicService.getClassesCount(queryParams);
		// System.out.println(list);
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		// System.out.println(listsize);
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);

	}

	// 查询所有树型的Classes
	@RequestMapping("KnowledgeclassListall")
	public void toKnowledgeclassListall(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<Classes> list1 = publicService.getClasses();
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		for (int i = 0; i < list1.size(); i++) {
			Classes Classes1 = list1.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", Classes1.getId());
			mp.put("name", Classes1.getNameZh() + "(" + Classes1.getNameEn()+ ")");
			mp.put("nameZh", Classes1.getNameZh());
			mp.put("nameEn", Classes1.getNameEn());
			mp.put("pId", Classes1.getClassesId());
			r.add(mp);
		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}
	// 查询所有资源库标识
	@RequestMapping("knowledgeDbAll")
	public void knowledgeDbAll(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		queryParams.put("=,name_en", "db");
		List<Dict> dictList = publicService.getDict(queryParams, 1, 1);
		if( null != dictList && dictList.size()>0){
			List<DictItem> dictItemList = publicService.getDictItem(dictList.get(0));
			LinkedHashMap<String, Object> mp = null;
			for (int i = 0; i < dictItemList.size(); i++) {
				DictItem dictItem = dictItemList.get(i);
				mp = new LinkedHashMap<String, Object>();
				mp.put("id", dictItem.getId());
				mp.put("name", dictItem.getNameZh() + "(" + dictItem.getNameEn()+ ")");
				mp.put("nameZh", dictItem.getNameZh());
				mp.put("nameEn", dictItem.getNameEn());
				mp.put("pId", dictItem.getLevel());
				mp.put("value", dictItem.getValue());
				r.add(mp);
			}
		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	//重构Class
	// 查询所有树型的Classes
	@RequestMapping("reconsitution")
	public void reconsitution(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String classnameEn = request.getParameter("classnameEn");
		//更新redis缓存数据
			dynamicService.saveObjectForCache();
		String pd="yes";
		try {
			dynamicService.editClassesDb(classnameEn);
		} catch (Exception e) {
			pd="no";
			e.printStackTrace();
		}
		List<String> r = new ArrayList<String>();
		r.add(pd);
		String result = formatToJson(r);

		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 保存Class
	@RequestMapping("KnowledgeClassesclasssave")
	public void toKnowledgeClassesclasssave(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String description = request.getParameter("description");
		String domainid = request.getParameter("domainid");
		String parentClassid = request.getParameter("parentClassid");
		String classid = request.getParameter("classid");
		String display = request.getParameter("display");
		String icon = request.getParameter("icon");
		String indexEntrance = request.getParameter("indexEntrance");
		String indexLatestUpdate = request.getParameter("indexLatestUpdate");
		String generalSearch = request.getParameter("generalSearch");
		String advancedSearch = request.getParameter("advancedSearch");
		String recommendClassEn = request.getParameter("recommendClassEn");
		String navigationDataType = request.getParameter("navigationDataType");
		String indeNavigation = request.getParameter("indeNavigation");
		String webListButtons = request.getParameter("webListButtons");
		String pay = request.getParameter("pay");
		String detailUrl = request.getParameter("detailUrl");
		String knowledgeDb = request.getParameter("knowledgeDb");
		Integer sort = Integer.parseInt(request.getParameter("sort").trim());
		User logUser = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		// 类的处理；
		Classes Classes1 = new Classes();
		if (id.equals("0")) {
			if (classid != null) {
				if (!parentClassid.equals("00")) {
					Classes1.setClassesId(Integer.parseInt(parentClassid));
				} else {
					Classes1.setClassesId(Integer.parseInt(classid));
				}
			} else {
				Classes1.setClassesId(0);
			}
		} else {
			Classes1.setClassesId(Integer.parseInt(parentClassid));
		}
		Classes1.setDescription(description);
		if ("1".equals(display)) {
			Classes1.setDisplay(1);
		} else {
			Classes1.setDisplay(0);
		}
		Classes1.setNameEn(nameEn);
		Classes1.setNameZh(nameZh);
		Classes1.setSort(sort);
		Classes1.setAdvancedSearch(advancedSearch);
		Classes1.setGeneralSearch(generalSearch);
		Classes1.setIcon(icon);
		Classes1.setIndexEntrance(indexEntrance);
		Classes1.setIndexLatestUpdate(indexLatestUpdate);
		Classes1.setRecommendClassEn(recommendClassEn);
		Classes1.setIndeNavigation(indeNavigation);
		Classes1.setNavigationDataType(Integer.parseInt(navigationDataType));
		Classes1.setWebListButtons(webListButtons);
		Classes1.setPay(Integer.parseInt(pay));
		Classes1.setDetailUrl(detailUrl);
		Classes1.setDb(knowledgeDb);
		
		Classes Classes2 = new Classes();
		if (id.equals("1")) {
			Classes1.setId(Integer.parseInt(classid));
			int logTime = 0;
			try {
				Classes2 = baseService.editClasses(Classes1);
			} catch (Exception e) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【修改】知识结构【" + nameZh
						+ "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【修改】知识结构【" + nameZh
						+ "】成功！", 0);
			}

		} else {
			int logTime = 0;
			try {
				Classes2 = baseService.saveClasses(Classes1);
			} catch (Exception e) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【新增】知识结构【" + nameZh
						+ "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(), "general_data", null, null, "【"
						+ logUser.getNickname() + "】【新增】知识结构【" + nameZh
						+ "】成功！", 0);
			}

		}
		dynamicService.saveObjectForCache();
		String result = formatToJson(Classes2);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 修改Class
	@RequestMapping("KnowledgeClassesclassedit")
	public void toKnowledgeClassesclassedit(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Classes Classes1 = publicService.findClasses(Integer.parseInt(id));
		HashMap<String, Object> r = new HashMap<String, Object>();
		r.put("classes", Classes1);
		Classes Classes2 = null;
		if (Classes1.getClassesId() != 0) {
			Classes2 = publicService.findClasses(Classes1.getClassesId());
			r.put("pid", Classes2);
		} else {
			r.put("pid", Classes2);
		}
		String recommendClassZh ="";
		if (Classes1.getRecommendClassEn() != null && !"".equals(Classes1.getRecommendClassEn())) {
			String [] classess = Classes1.getRecommendClassEn().split(";");
			List<Classes> classesList = publicService.getClasses();
			for (int i = 0; i < classess.length; i++) {
				for (int j = 0; j < classesList.size(); j++) {
					if(classess[i].equals(classesList.get(j).getNameEn())){
						recommendClassZh += classesList.get(j).getNameZh()+";";
					}
					
				}
				
			}
			
		}
		if(recommendClassZh != null && !"".equals(recommendClassZh)){
			recommendClassZh = recommendClassZh.substring(0, recommendClassZh.length()-1);
		}
		r.put("recommendClassZh", recommendClassZh);
		String buttonName = "";
		String webListButtons = Classes1.getWebListButtons();
		if(webListButtons != null && !"".equals(webListButtons)){
			String values[] = webListButtons.split(";");
			HashMap<String, Object> querydictParams = new HashMap<String, Object>();
			querydictParams.put("=,name_en", "web_list_buttons");
			List<Dict> dictList = publicService.getDict(querydictParams, 1, 1);
			if(null !=dictList && dictList.size()>0){
				HashMap<String, Object> queryParams = null;
				Dict dict = dictList.get(0);
				for (int i = 0; i < values.length; i++) {
					queryParams = new HashMap<String, Object>();
					queryParams.put("=,dict_id", dict.getId());
					queryParams.put("=,value", values[i]);
					List<DictItem> dictItemList = publicService.getDictItem(queryParams, 1, 1);
					if(null != dictItemList && dictItemList.size() > 0){
						DictItem dictItem = dictItemList.get(0);
						buttonName += dictItem.getNameZh()+";";
					}
				}
			}
		}
		r.put("ClassesbuttonName", buttonName);
		String dbName = "";
		String db = Classes1.getDb();
		if(db != null && !"".equals(db)){
			String dbValues[] = db.split(";");
			HashMap<String, Object> querydbdictParams = new HashMap<String, Object>();
			querydbdictParams.put("=,name_en", "db");
			List<Dict> dictList = publicService.getDict(querydbdictParams, 1, 1);
			if(null !=dictList && dictList.size()>0){
				HashMap<String, Object> queryParams = null;
				Dict dict = dictList.get(0);
				for (int i = 0; i < dbValues.length; i++) {
					queryParams = new HashMap<String, Object>();
					queryParams.put("=,dict_id", dict.getId());
					queryParams.put("=,value", dbValues[i]);
					List<DictItem> dictItemList = publicService.getDictItem(queryParams, 1, 1);
					if(null != dictItemList && dictItemList.size() > 0){
						DictItem dictItem = dictItemList.get(0);
						dbName += dictItem.getNameZh()+";";
					}
				}
			}
		}
		r.put("dbName", dbName);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 跳转导入Class页面
	@RequestMapping("knowledge_DataProperty_class_import.html")
	public String toKnowledgeDataPropertyclassImport() {

		return "/modules/knowledgedata/knowledge_DataProperty_class_import";
	}

	// 导入Class
	// 数据导入{导入数据处理}
	@RequestMapping("classImportdownload")
	public void toClassImportdownload(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// 解析文件，生成document对象
		String id=request.getParameter("id");
		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
				.newDocumentBuilder();
		//String path =  request.getContextPath() + id;
		String path = request.getSession().getServletContext().getRealPath("\\")
				+id;

		Document document = builder.parse(new File(
				path));
		Map<Object, Integer> classessMap= new LinkedHashMap<Object, Integer>();
		// 生成XPath对象
		XPath xpath = XPathFactory.newInstance().newXPath();
		// 获取节点集合
		NodeList f_subject = (NodeList) xpath.evaluate("//Classes", document, XPathConstants.NODESET);
		
		for (int i = 0; i < f_subject.getLength(); i++) {
			Node subject = f_subject.item(i);
			//属性id
		String iddata=xpath.evaluate("@id", subject, XPathConstants.STRING).toString();
		String classesId=xpath.evaluate("@classesId", subject, XPathConstants.STRING).toString();
		
		 //一级所有值
		 
		String nameEn = xpath.evaluate("nameEn", subject, XPathConstants.STRING).toString();
		String nameZh = xpath.evaluate("nameZh", subject, XPathConstants.STRING).toString();
		String description = xpath.evaluate("description",subject,XPathConstants.STRING).toString();
		String display = xpath.evaluate("display",subject,XPathConstants.STRING).toString();
		String sort = xpath.evaluate("sort", subject,XPathConstants.STRING).toString();
		
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		queryParams.put("=,nameEn", nameEn);
		queryParams.put("=,nameZh", nameZh);
		long cs = publicService.getClassesCount(queryParams);
		if(cs == 0){
			Classes classes = new Classes();
			classes.setClassesId(Integer.parseInt(classesId));
			classes.setNameEn(nameEn);
			classes.setNameZh(nameZh);
			classes.setDescription(description);
			classes.setDisplay(Integer.parseInt(display));
			classes.setSort(Integer.parseInt(sort));
			baseService.saveClasses(classes);
			List<Classes> Classess =publicService.getClasses(queryParams, 1, publicService.getClassesCount(queryParams).intValue());
			for (int j = 0; j < Classess.size(); j++) {
				Classes classes2=Classess.get(j);
				classessMap.put(iddata, classes2.getId());
			}
		}
		// 获取节点集合
		NodeList d_subject = (NodeList) xpath.evaluate("//Dict", document, XPathConstants.NODESET);
		for (int k = 0; k < d_subject.getLength(); k++) {
		Node dsubject = d_subject.item(k);
		String idDict=xpath.evaluate("@id", dsubject, XPathConstants.STRING).toString();
		 //一级所有值
		 
		String nameEnDict = xpath.evaluate("nameEn", dsubject, XPathConstants.STRING).toString();
		String nameZhDict = xpath.evaluate("nameZh", dsubject, XPathConstants.STRING).toString();
		String dictType = xpath.evaluate("dictType",dsubject,XPathConstants.STRING).toString();
		String sortDict = xpath.evaluate("sort", dsubject,XPathConstants.STRING).toString();
		
		HashMap<String, Object> queryParamsDict = new LinkedHashMap<String, Object>();
		queryParamsDict.put("=,nameEn", nameEnDict);
		queryParamsDict.put("=,nameZh", nameZhDict);
		long ds = publicService.getDictCount(queryParamsDict);
		if(ds == 0){
			Dict dict = new Dict();
			//dict.setId(Integer.parseInt(dictId));
			dict.setNameEn(nameEnDict);
			dict.setNameZh(nameZhDict);
			dict.setDictType(Integer.parseInt(dictType));
			dict.setSort(Integer.parseInt(sortDict));
			baseService.saveDict(dict);
		}	
	}
		// 获取节点集合
		NodeList di_subject = (NodeList) xpath.evaluate("//DictItem", document, XPathConstants.NODESET);
		for (int k = 0; k < di_subject.getLength(); k++) {
		Node diSubject = di_subject.item(k);
		String idDictItem=xpath.evaluate("@id", diSubject, XPathConstants.STRING).toString();
		String dictId=xpath.evaluate("@dictNameEn", diSubject, XPathConstants.STRING).toString();
		String dictItemId=xpath.evaluate("@dictItemNameEn", diSubject, XPathConstants.STRING).toString();
		 //一级所有值
		 
		String nameEnDictItem = xpath.evaluate("nameEn", diSubject, XPathConstants.STRING).toString();
		String nameZhDictItem = xpath.evaluate("nameZh", diSubject, XPathConstants.STRING).toString();
		String value = xpath.evaluate("value",diSubject,XPathConstants.STRING).toString();
		String sortDictItem = xpath.evaluate("sort", diSubject,XPathConstants.STRING).toString();
		
		HashMap<String, Object> queryParamsDictItem = new LinkedHashMap<String, Object>();
		queryParamsDictItem.put("=,nameEn", nameEnDictItem);
		queryParamsDictItem.put("=,nameZh", nameZhDictItem);
		long di = publicService.getDictItemCount(queryParamsDictItem);
		if(di == 0){
			DictItem dictItem = new DictItem();
			HashMap<String, Object> dictmap = new LinkedHashMap<String, Object>();
			dictmap.put("=,nameEn", dictId);
			List<Dict> dictList=publicService.getDict(dictmap, 1, publicService.getDictCount(dictmap).intValue());
			for (int j = 0; j < dictList.size(); j++) {
				dictItem.setDictId(dictList.get(j).getId());
			}
			if(dictItemId != null && !"".equals(dictItemId)){
				if("0".equals(dictItemId) || "".equals(dictItemId)){
					dictItem.setDictItemId(0);
				}else{
					HashMap<String, Object> dictItemmap = new LinkedHashMap<String, Object>();
					dictItemmap.put("=,nameEn", dictItemId);
					List<DictItem> dictItemList=publicService.getDictItem(dictItemmap, 1, publicService.getDictItemCount(dictItemmap).intValue());
					for (int j = 0; j < dictItemList.size(); j++) {
						dictItem.setDictItemId(dictItemList.get(j).getId());
					}
				}
			}
			dictItem.setNameEn(nameEnDictItem);
			dictItem.setNameZh(nameZhDictItem);
			dictItem.setValue(value);
			dictItem.setSort(Integer.parseInt(sortDictItem));
			baseService.saveDictItem(dictItem);
		}	
	}
			// 获取节点集合
		NodeList l_subject = (NodeList) xpath.evaluate("//DataProperty", document, XPathConstants.NODESET);
		for (int k = 0; k < l_subject.getLength(); k++) {
		Node lsubject = l_subject.item(k);
		String idDataProperty=xpath.evaluate("@id", lsubject, XPathConstants.STRING).toString();
		String classesIdDataProperty=xpath.evaluate("@classesId", lsubject, XPathConstants.STRING).toString();
		
		 //一级所有值
		 
		String nameEnDataProperty = xpath.evaluate("nameEn", lsubject, XPathConstants.STRING).toString();
		String nameZhDataProperty = xpath.evaluate("nameZh", lsubject, XPathConstants.STRING).toString();
		String commonDataPropertyId = xpath.evaluate("commonDataPropertyId",lsubject,XPathConstants.STRING).toString();
		String dataTypeId = xpath.evaluate("dataTypeId",lsubject,XPathConstants.STRING).toString();
		String fieldLength = xpath.evaluate("fieldLength", lsubject,XPathConstants.STRING).toString();
		String field = xpath.evaluate("field", lsubject, XPathConstants.STRING).toString();
		String dictId = xpath.evaluate("dictNameEn", lsubject, XPathConstants.STRING).toString();
		String separator = xpath.evaluate("separator",lsubject,XPathConstants.STRING).toString();
		String solrIndexField = xpath.evaluate("solrIndexField",lsubject,XPathConstants.STRING).toString();
		String multiValued = xpath.evaluate("multiValued", lsubject,XPathConstants.STRING).toString();
		String required = xpath.evaluate("required", lsubject, XPathConstants.STRING).toString();
		String stored = xpath.evaluate("stored", lsubject, XPathConstants.STRING).toString();
		String indexed = xpath.evaluate("indexed",lsubject,XPathConstants.STRING).toString();
		String termVectors = xpath.evaluate("termVectors",lsubject,XPathConstants.STRING).toString();
		String faceted = xpath.evaluate("faceted", lsubject,XPathConstants.STRING).toString();
		String sortField = xpath.evaluate("sortField", lsubject, XPathConstants.STRING).toString();
		String webListShow = xpath.evaluate("webListShow",lsubject,XPathConstants.STRING).toString();
		String webDetailShow = xpath.evaluate("webDetailShow",lsubject,XPathConstants.STRING).toString();
		String adminListShow = xpath.evaluate("adminListShow", lsubject,XPathConstants.STRING).toString();
		String adminDetailShow = xpath.evaluate("adminDetailShow", lsubject, XPathConstants.STRING).toString();
		String relevanceClassShowField = xpath.evaluate("relevanceClassShowField",lsubject,XPathConstants.STRING).toString();
		String formValidationRegulation = xpath.evaluate("formValidationRegulation",lsubject,XPathConstants.STRING).toString();
		String sortDataProperty = xpath.evaluate("sort", lsubject,XPathConstants.STRING).toString();
		
		List<DataProperty> list = publicService.getDataProperty();
		int pd = 0;
		for (int j = 0; j < list.size(); j++) {
			DataProperty dataProperty = list.get(j);
			if(dataProperty.getNameEn().equals(nameEnDataProperty)){
				pd=1;
			}	
		  }
			if(pd == 0){
				DataProperty dProperty = new DataProperty();
				dProperty.setClassesId(classessMap.get(classesIdDataProperty));
				dProperty.setNameEn(nameEnDataProperty);
				dProperty.setNameZh(nameZhDataProperty);
				dProperty.setCommonDataPropertyId(Integer.parseInt(commonDataPropertyId));
				dProperty.setDataTypeId(Integer.parseInt(dataTypeId));
				dProperty.setSeparator(separator);
				dProperty.setFieldLength(Integer.parseInt(fieldLength));
				dProperty.setField(field);
				dProperty.setSortField(solrIndexField);
				dProperty.setRequired(required);
				HashMap<String, Object> dictmap = new LinkedHashMap<String, Object>();
				dictmap.put("=,nameEn", dictId);
				List<Dict> dictList=publicService.getDict(dictmap, 1, publicService.getDictCount(dictmap).intValue());
				if(dictList.size()>0){
					for (int j = 0; j < dictList.size(); j++) {
						dProperty.setDictId(dictList.get(j).getId());
					}
				}else{
					dProperty.setDictId(0);
				}
				dProperty.setMultiValued(multiValued);
				dProperty.setStored(stored);
				dProperty.setIndexed(indexed);
				dProperty.setTermVectors(termVectors);
				dProperty.setFaceted(faceted);
				dProperty.setSortField(sortField);
				dProperty.setWebListShow(webListShow);
				dProperty.setWebDetailShow(webDetailShow);
				dProperty.setAdminListShow(adminListShow);
				dProperty.setAdminDetailShow(adminDetailShow);
				dProperty.setRelevanceClassShowField(relevanceClassShowField);
				dProperty.setFormValidationRegulation(formValidationRegulation);
				dProperty.setSort(Integer.parseInt(sortDataProperty));
				baseService.saveDataProperty(dProperty);
			}
		}
		// 获取节点集合
		NodeList o_subject = (NodeList) xpath.evaluate("//ObjectProperty", document, XPathConstants.NODESET);
		for (int k = 0; k < o_subject.getLength(); k++) {
		Node osubject = o_subject.item(k);
		String idObjectProperty=xpath.evaluate("@id", osubject, XPathConstants.STRING).toString();
		String classesIdObjectProperty=xpath.evaluate("@classesNameEn", osubject, XPathConstants.STRING).toString();
		 //一级所有值
		 
		String nameEnObjectProperty = xpath.evaluate("nameEn", osubject, XPathConstants.STRING).toString();
		String nameZhObjectProperty = xpath.evaluate("nameZh", osubject, XPathConstants.STRING).toString();
		String commonObjectPropertyId = xpath.evaluate("commonObjectPropertyId",osubject,XPathConstants.STRING).toString();
		String relevanceClassesId = xpath.evaluate("relevanceClassesId", osubject,XPathConstants.STRING).toString();
		String relevanceClassFields = xpath.evaluate("relevanceClassFields", osubject,XPathConstants.STRING).toString();
		String field = xpath.evaluate("field", osubject,XPathConstants.STRING).toString();
		String multiValued = xpath.evaluate("multiValued", osubject,XPathConstants.STRING).toString();
		String required = xpath.evaluate("required", osubject,XPathConstants.STRING).toString();
		String stored = xpath.evaluate("stored", osubject,XPathConstants.STRING).toString();
		String indexed = xpath.evaluate("indexed", osubject,XPathConstants.STRING).toString();
		String termVectors = xpath.evaluate("termVectors", osubject,XPathConstants.STRING).toString();
		String webListShow = xpath.evaluate("webListShow", osubject,XPathConstants.STRING).toString();
		String webDetailShow = xpath.evaluate("webDetailShow", osubject,XPathConstants.STRING).toString();
		String adminListShow = xpath.evaluate("adminListShow", osubject,XPathConstants.STRING).toString();
		String adminDetailShow = xpath.evaluate("adminDetailShow", osubject,XPathConstants.STRING).toString();
		String sortObjectProperty = xpath.evaluate("sort", osubject,XPathConstants.STRING).toString();
		
		
		
		List<ObjectProperty> list = publicService.getObjectProperty();
		int op = 0;
		for (int j = 0; j < list.size(); j++) {
			ObjectProperty objectProperty = list.get(j);
			if(objectProperty.getNameEn().equals(nameEnObjectProperty)){
				op=1;
			}	
		  }
			if(op == 0){
				ObjectProperty oProperty = new ObjectProperty();
				HashMap<String, Object> queryParamsObjectProperty = new LinkedHashMap<String, Object>();
				queryParamsObjectProperty.put("=,nameEn", classesIdObjectProperty);
				List<Classes> Classess =publicService.getClasses(queryParamsObjectProperty, 1, publicService.getClassesCount(queryParamsObjectProperty).intValue());
				for (int j = 0; j < Classess.size(); j++) {
					oProperty.setClassesId(Classess.get(j).getId());
				}
				oProperty.setNameEn(nameEnObjectProperty);
				oProperty.setNameZh(nameZhObjectProperty);
				oProperty.setCommonObjectPropertyId(Integer.parseInt(commonObjectPropertyId));
				oProperty.setRelevanceClassFields(relevanceClassFields);
				oProperty.setRelevanceClassesId(Integer.parseInt(relevanceClassesId));
				oProperty.setField(field);
				oProperty.setMultiValued(multiValued);
				oProperty.setRequired(required);
				oProperty.setStored(stored);
				oProperty.setIndexed(indexed);
				oProperty.setTermVectors(termVectors);
				oProperty.setWebListShow(webListShow);
				oProperty.setWebDetailShow(webDetailShow);
				oProperty.setAdminListShow(adminListShow);
				oProperty.setAdminDetailShow(adminDetailShow);
				oProperty.setSort(Integer.parseInt(sortObjectProperty));
				baseService.saveObjectProperty(oProperty);
			}
	}
}
		String result = "{\"result\":" + "\"ok\"}";
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	
	

	// 删除Class
	@RequestMapping("KnowledgeClassesclassdel")
	public void toKnowledgeClassesclassdel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		int counts= 1;
		Classes Classes1 = publicService.findClasses(Integer.parseInt(id));
		
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		queryParams.put("%,classesIds", Classes1.getId()+",");
		int repositoryProductCount =  publicService.getRepositoryProductCount(queryParams);
		
		HashMap<String, Object> querySearchParams = new LinkedHashMap<String, Object>();
		querySearchParams.put("=,classes_en", Classes1.getId());
		int searchWeightFieldsCount = publicService.getSearchWeightFieldsCount(querySearchParams);
		
		HashMap<String, Object> queryExportParams = new LinkedHashMap<String, Object>();
		queryExportParams.put("=,classes_id", Classes1.getId());
		int dataExportCount = publicService.getDataExportCount(queryExportParams);
		
		HashMap<String, Object> queryImportParams = new LinkedHashMap<String, Object>();
		queryImportParams.put("=,classes_id", Classes1.getId());
		int dataImportCount = publicService.getDataImportCount(queryImportParams);
		
		HashMap<String, Object> queryHandlingParams = new LinkedHashMap<String, Object>();
		queryHandlingParams.put("=,classes_id", Classes1.getId());
		int dataHandlingCount = dataHandlingService.getDataHandlingCount(queryHandlingParams);
		
		HashMap<String, Object> queryInterfaceParams = new LinkedHashMap<String, Object>();
		queryInterfaceParams.put("=,classes_id", Classes1.getId());
		int dataInterfaceCount = publicService.getDataInterfaceCount(queryInterfaceParams);
		
		if(repositoryProductCount == 0 && searchWeightFieldsCount == 0 && dataExportCount == 0 && dataImportCount == 0 && dataHandlingCount == 0 && dataInterfaceCount == 0){
			counts = 0;
			List<DataProperty> dataProperty = publicService.getDataProperty(Classes1);
			List<ObjectProperty> objectProperty = publicService.getObjectProperty(Classes1);
			int logTime = 0;
			User logUser = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
			try {
				for (int i = 0; i < dataProperty.size(); i++) {
					baseService.deleteDataProperty(dataProperty.get(i));
				}
				for (int i = 0; i < objectProperty.size(); i++) {
					baseService.deleteObjectProperty(objectProperty.get(i));
				}
				HashMap<String, Object> queryPermissionClassesParams = new HashMap<String, Object>();
				queryPermissionClassesParams.put("=,classes_id", id);
				List<PermissionClasses> permissionClassesList = publicService.getPermissionClasses(queryPermissionClassesParams);
				for (int i = 0; i < permissionClassesList.size(); i++) {
					baseService.deletePermissionClasses(permissionClassesList.get(i));
				}
				baseService.deleteClasses(Classes1);
			} catch (Exception e) {
				this.Log(logUser.getId(),"general_data",null,null,"【" + logUser.getNickname() + "】【删除】知识结构【"+ Classes1.getNameZh() + "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(logUser.getId(),"general_data",null,null,"【" + logUser.getNickname() + "】【删除】知识结构【"+ Classes1.getNameZh() + "】成功！", 0);
			}
		}
		dynamicService.saveObjectForCache();

		String result = "{\"result\":" + "\""+counts+"\"}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 验证class的NameEn是否重名
	@RequestMapping("KnowledgeclassProving")
	public void toKnowledgeclassProving(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String name = request.getParameter("name");
		// System.out.println(name);
		List<Classes> list1 = publicService.getClasses();
		int falg = 1;
		for (int i = 0; i < list1.size(); i++) {
			if (name.equals(list1.get(i).getNameEn())) {
				falg = 2;
			}
		}
		boolean falg1 = ValidateSQL.Proving(name);
		if (!falg1) {
			falg = 3;
		}
		boolean falg2 = ValidateSQL.Provname(name);
		if (!falg2) {
			falg = 4;
		}
		String result = "{\"result\":" + falg + "}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}
	
	// 检索结果页显示按钮
	@RequestMapping("showKnowledgeClassesButton")
	public void showKnowledgeClassesButton(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String page = request.getParameter("page");
		String dictItemEn = request.getParameter("dictItemEn");
		LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
		HashMap<String, Object> querydictParams = new HashMap<String, Object>();
		querydictParams.put("=,name_en", dictItemEn);
		List<Dict> dictList = publicService.getDict(querydictParams, 1, 1);
		if(null !=dictList && dictList.size()>0){
			Dict dict = dictList.get(0);
			HashMap<String, Object> queryParams = new HashMap<String, Object>();
			queryParams.put("=,dict_id", dict.getId());
			List<DictItem> dictItemList = publicService.getDictItem(queryParams, Integer.parseInt(page), 10);
			int count = publicService.getDictItemCount(queryParams);
			mp.put("data", dictItemList);
			mp.put("count", count);
			mp.put("page", (int)Math.ceil(Double.valueOf(count)/10));
		}
		String result = formatToJson(mp);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}
	/*
	 * 发布redis
	 */

	// 发布redis
	@RequestMapping("Knowledgeredis")
	public void toKnowledgeredis(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		dynamicService.saveObjectForCache();
	}

	/*
	 * DataProperty管理
	 */

	// 跳转DataProperty数据类型 ----修改页面；
	@RequestMapping("knowledge-DataProperty-class-from.html")
	public String toKnowledgeDataPropertyclassEdit() {

		return "/modules/knowledgedata/knowledge_DataProperty_class_from";
	}

	// 删除DataProperty数据
	@RequestMapping("KnowledgeDataPropertydel")
	public void toKnowledgeDataPropertydel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataProperty DataProperty1 = new DataProperty();
		// DataProperty1.setId(Integer.parseInt(id));
		DataProperty1 = publicService.findDataProperty(Integer.parseInt(id));
		int logTime = 0;
		User logUser = publicService.findUser((Integer) request.getSession()
				.getAttribute("userid"));
		Classes classes = publicService.findClasses(DataProperty1
				.getClassesId());
		try {
			baseService.deleteDataProperty(DataProperty1);
		} catch (Exception e) {
			this.Log(
					logUser.getId(),
					"general_data",
					null,
					null,
					"【" + logUser.getNickname() + "】【删除】知识结构【"
							+ classes.getNameZh() + "】数据属性【"
							+ DataProperty1.getNameZh() + "】失败！请检查数据是否正确！", 1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.Log(
					logUser.getId(),
					"general_data",
					null,
					null,
					"【" + logUser.getNickname() + "】【删除】知识结构【"
							+ classes.getNameZh() + "】数据属性【"
							+ DataProperty1.getNameZh() + "】成功！", 0);
		}

		dynamicService.saveObjectForCache();
		String result = "{\"result\":" + "\"ok\"}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 查询DataProperty
	@RequestMapping("KnowledgeDataPropertyList")
	public void toKnowledgeDataPropertyList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("lid");
		Classes Classes1 = publicService.findClasses(Integer.parseInt(id));
		List<DataProperty> list1 = publicService.getDataProperty(Classes1);
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		for (int i = 0; i < list1.size(); i++) {
			DataProperty DataProperty1 = list1.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", DataProperty1.getId());
			mp.put("name", DataProperty1.getNameZh());
			mp.put("nameen", DataProperty1.getNameEn());
			mp.put("field", DataProperty1.getField());
			r.add(mp);
		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 保存DataProperty
	@RequestMapping("KnowledgeDataPropertysave")
	public void toKnowledgeDataPropertysave(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String classid = request.getParameter("classid");
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String separator = request.getParameter("separator");
		String dataTypeid = request.getParameter("dataType");
		String dictid = request.getParameter("dict");
		String fieldLength = request.getParameter("fieldLength");
		String commonDataPropertyid = request.getParameter("commonDataProperty");
		String field = request.getParameter("field");
		String count = request.getParameter("count");
		String formValidationRegulation = request.getParameter("formValidationRegulation");
		String generalSearchField = request.getParameter("generalSearchField");
		String advancedSearchField = request.getParameter("advancedSearchField");
		String searchWithinResultsField = request.getParameter("searchWithinResultsField");
		String highlightingField = request.getParameter("highlightingField");
		String navigationFacetedLeft = request.getParameter("navigationFacetedLeft");
		String navigationFacetedRight = request.getParameter("navigationFacetedRight");
		String navigationSearchField = request.getParameter("navigationSearchField");
		String productGeneralSearchField = request.getParameter("productGeneralSearchField");
		String productAdvancedSearchField = request.getParameter("productAdvancedSearchField");
		String productFaceted = request.getParameter("productFaceted");
		String productWebListShow = request.getParameter("productWebListShow");
		String productWebDetailShow = request.getParameter("productWebDetailShow");
		if(null==formValidationRegulation) {
			formValidationRegulation="";
		}
		Integer sort = Integer.parseInt(request.getParameter("sort"));
		DataProperty DataProperty1 = new DataProperty();
		// System.out.println(fieldLength);
		DataProperty1.setFieldLength(Integer.parseInt(fieldLength));
		DataProperty1.setClassesId(Integer.parseInt(classid));
		DataProperty1.setCommonDataPropertyId(Integer.parseInt(commonDataPropertyid));
		DataProperty1.setDataTypeId(Integer.parseInt(dataTypeid));
		DataProperty1.setDictId(Integer.parseInt(dictid));
		DataProperty1.setNameEn(nameEn);
		DataProperty1.setSeparator(separator);
		DataProperty1.setMultiValued(request.getParameter("multiValued"));
		DataProperty1.setRequired(request.getParameter("required"));
		DataProperty1.setStored(request.getParameter("stored"));
		DataProperty1.setIndexed(request.getParameter("indexed"));
		DataProperty1.setTermVectors(request.getParameter("termVectors"));
		DataProperty1.setFaceted(request.getParameter("faceted"));
		DataProperty1.setSortField(request.getParameter("sortField"));
		DataProperty1.setWebListShow(request.getParameter("webListShow"));
		DataProperty1.setWebDetailShow(request.getParameter("webDetailShow"));
		DataProperty1.setAdminListShow(request.getParameter("adminListShow"));
		DataProperty1.setAdminDetailShow(request.getParameter("adminDetailShow"));
		DataProperty1.setRelevanceClassShowField(request.getParameter("relevanceClassShowField"));
		DataProperty1.setFormValidationRegulation(formValidationRegulation);
		DataProperty1.setNameZh(nameZh);
		DataProperty1.setField(field);
		DataProperty1.setSort(sort);
		DataProperty1.setGeneralSearchField(generalSearchField);
		DataProperty1.setSearchWithinResultsField(searchWithinResultsField);
		DataProperty1.setAdvancedSearchField(advancedSearchField);
		DataProperty1.setHighlightingField(highlightingField);
		DataProperty1.setNavigationFacetedLeft(navigationFacetedLeft);
		DataProperty1.setNavigationFacetedRight(navigationFacetedRight);
		DataProperty1.setNavigationSearchField(navigationSearchField);
		DataProperty1.setProductGeneralSearchField(productGeneralSearchField);
		DataProperty1.setProductAdvancedSearchField(productAdvancedSearchField);
		DataProperty1.setProductFaceted(productFaceted);
		DataProperty1.setProductWebListShow(productWebListShow);
		DataProperty1.setProductWebDetailShow(productWebDetailShow);
		User logUser = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		Classes classes = publicService.findClasses(Integer.parseInt(classid));
		List<DataProperty> dataPropertyList =publicService.getDataProperty(classes);
		int zisucount =Integer.parseInt(fieldLength);
		String returnjieguo="no";
		for (int i = 0; i < dataPropertyList.size(); i++) {
			DataProperty dataProperty =dataPropertyList.get(i);
			zisucount +=  dataProperty.getFieldLength();
		}
		if(zisucount <= 21843){
			returnjieguo="ok";
			if (!id.equals("0")) {
				DataProperty1.setId(Integer.parseInt(id));
				int logTime = 0;
				try {
					baseService.editDataProperty(DataProperty1);
				} catch (Exception e) {
					this.Log(
							logUser.getId(),
							"general_data",
							null,
							null,
							"【" + logUser.getNickname() + "】【修改】知识结构【"
									+ classes.getNameZh() + "】数据属性【" + nameZh
									+ "】失败！请检查数据是否正确！", 1);
					logTime = 1;
					e.printStackTrace();
				}
				if (logTime == 0) {
					this.Log(
							logUser.getId(),
							"general_data",
							null,
							null,
							"【" + logUser.getNickname() + "】【修改】知识结构【"
									+ classes.getNameZh() + "】数据属性【" + nameZh
									+ "】成功！", 0);
				}
	
			} else {
				int logTime = 0;
				try {
					 baseService.saveDataProperty(DataProperty1);
				} catch (Exception e) {
					this.Log(
							logUser.getId(),
							"general_data",
							null,
							null,
							"【" + logUser.getNickname() + "】【新增】知识结构【"
									+ classes.getNameZh() + "】数据属性【" + nameZh
									+ "】失败！请检查数据是否正确！", 1);
					logTime = 1;
					e.printStackTrace();
				}
				if (logTime == 0) {
					this.Log(
							logUser.getId(),
							"general_data",
							null,
							null,
							"【" + logUser.getNickname() + "】【新增】知识结构【"
									+ classes.getNameZh() + "】数据属性【" + nameZh
									+ "】成功！", 0);
				}
	
			}
		}
		// String result = formatToJson(DataProperty2);
		List<String> r = new ArrayList<String>();
		r.add(returnjieguo);
		String result = formatToJson(r);
		dynamicService.saveObjectForCache();
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 保存DataProperty根据字符串，获取字段的值 true或者false
	public static boolean getboolean(String kk, String count) {
		char a = count.charAt(count.indexOf(kk) + 1 + kk.length());
		if (a == '0') {
			return false;
		} else {
			return true;
		}
	}

	// 修改DataProperty
	@RequestMapping("KnowledgeDataPropertyedit")
	public void toKnowledgeDataPropertyedit(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		// System.out.println(id);
		Map<String,Object> map = new HashMap<String, Object>();
		DataProperty DataProperty1 = publicService.findDataProperty(Integer.parseInt(id));
		CommonDataProperty aCommonDataProperty = null;
		if (DataProperty1.getCommonDataPropertyId() != 0) {
			aCommonDataProperty = publicService.findCommonDataProperty(DataProperty1.getCommonDataPropertyId());
			map.put("commonDataProperty", aCommonDataProperty);
			//DataProperty1.setCommonDataProperty(aCommonDataProperty);
		} else {
			map.put("commonDataProperty", null);
			//DataProperty1.setCommonDataProperty(aCommonDataProperty);
		}
		DataType aDataType = new DataType();
		if (DataProperty1.getDataTypeId() != 0) {
			aDataType = publicService.findDataType(DataProperty1.getDataTypeId());
			map.put("dataType", aDataType);
			//DataProperty1.setDataType(aDataType);
		} else {
			map.put("dataType", null);
			//DataProperty1.setDataType(aDataType);
		}
		Dict aDict = new Dict();
		if (DataProperty1.getDictId() != 0) {
			aDict = publicService.findDict(DataProperty1.getDictId());
			map.put("dict", aDict);
			//DataProperty1.setDict(aDict);
		} else {
			map.put("dict", null);
			//DataProperty1.setDict(aDict);
		}

		Classes Classes2 = publicService.findClasses(DataProperty1.getClassesId());
		map.put("Classes", Classes2);
		
		map.put("text", DataProperty1);
		//DataProperty1.setClasses(Classes2);
		String result = formatToJson(map);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 验证DataProperty和ObjectProperty的NameEn是否重名
	@RequestMapping("KnowledgeDataPropertyProving")
	public void toKnowledgeDataPropertyProving(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String name = request.getParameter("name");
		String id = request.getParameter("id");
		String commonObjectPropertyId = request
				.getParameter("commonDataProperty");
		String objectPropertyId = request
				.getParameter("commonObjectPropertyId");
		// System.out.println(name);
		Classes classes = publicService.findClasses(Integer.parseInt(id));
		List<DataProperty> list1 = publicService.getDataProperty();
		List<ObjectProperty> list2 = publicService.getObjectProperty();
		List<CommonDataProperty> commonDataProperty = publicService
				.getCommonDataProperty();
		List<CommonObjectProperty> commonObjectProperty = publicService
				.getCommonObjectProperty();
		int falg = 1;
		if (commonObjectPropertyId != null) {
			if (Integer.parseInt(commonObjectPropertyId) == 00) {
				for (int j = 0; j < commonDataProperty.size(); j++) {
					CommonDataProperty cdp = commonDataProperty.get(j);
					if (cdp.getNameEn().equals(name)) {
						falg = 5;
					}

				}
				if (falg == 1) {
					for (int i = 0; i < list1.size(); i++) {
						DataProperty dp = list1.get(i);
						if (name.equals(dp.getNameEn())) {
							if (dp.getCommonDataPropertyId() == 0) {
								falg = 6;
								break;
							}
						}
					}
				}
			} else {
				List<DataProperty> dataProperty = publicService
						.getDataProperty(classes);
				if (dataProperty.size() > 0) {
					for (int i = 0; i < dataProperty.size(); i++) {
						DataProperty dp = dataProperty.get(i);
						if (dp.getNameEn().equals(name)) {
							falg = 2;
						}
					}
				}
			}
		}
		if (objectPropertyId != null) {
			if (Integer.parseInt(objectPropertyId) == 00) {
				for (int j = 0; j < commonObjectProperty.size(); j++) {
					CommonObjectProperty cdp = commonObjectProperty.get(j);
					if (cdp.getNameEn().equals(name)) {
						falg = 5;
					}

				}
				if (falg == 1) {
					for (int i = 0; i < list2.size(); i++) {
						ObjectProperty dp = list2.get(i);
						if (name.equals(dp.getNameEn())) {
							falg = 6;
							break;
						}
					}
				}
			} else {
				List<ObjectProperty> objectProperty = publicService
						.getObjectProperty(classes);
				if (objectProperty.size() > 0) {
					for (int i = 0; i < objectProperty.size(); i++) {
						ObjectProperty op = objectProperty.get(i);
						if (op.getNameEn().equals(name)) {
							falg = 2;
						}
					}
				}
			}

		}

		// 验证SQL是否冲突
		boolean falg1 = ValidateSQL.Proving(name);
		if (!falg1) {
			falg = 3;
		}
		// 验证是否为英文
		boolean falg2 = ValidateSQL.Provname(name);
		if (!falg2) {
			falg = 4;
		}
		String result = "{\"result\":" + falg + "}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	/*
	 * ObjectProperty管理
	 */
	// 跳转DataProperty对象类型----添加页面
	@RequestMapping("knowledge-DataProperty-data-from.html")
	public String toKnowledgeDataPropertydataEdit() {

		return "/modules/knowledgedata/knowledge_DataProperty_data_from";
	}

	// 跳转DataProperty对象类型----字段
	@RequestMapping("knowledge-DataProperty-class-Fields.html")
	public String toKnowledgeDataPropertyFields() {

		return "/modules/knowledgedata/knowledge_DataProperty_class_Fields";
	}

	// 保存ObjectProperty
	@RequestMapping("KnowledgeObjectPropertysave")
	public void toKnowledgeObjectPropertysave(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String classid = request.getParameter("classid");
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String separator = request.getParameter("separator");
		String commonObjectPropertyId = request.getParameter("commonObjectPropertyId");
		String field = request.getParameter("field");
		String count = request.getParameter("count");
		String relevanceClassesId = request.getParameter("relevanceClassesId");
		String relevanceClassFields = request
				.getParameter("relevanceClassFields");
		Integer sort = Integer.parseInt(request.getParameter("sort"));

		ObjectProperty aObjectProperty = new ObjectProperty();

		aObjectProperty.setNameEn(nameEn);
		aObjectProperty.setNameZh(nameZh);
		aObjectProperty.setField(field);
		aObjectProperty.setSort(sort);
		aObjectProperty.setClassesId(Integer.parseInt(classid));
		aObjectProperty.setCommonObjectPropertyId(Integer.parseInt(commonObjectPropertyId));
		aObjectProperty.setRelevanceClassesId(Integer.parseInt(relevanceClassesId));
		aObjectProperty.setRelevanceClassFields(relevanceClassFields);
		aObjectProperty.setMultiValued(request.getParameter("multiValued"));
		aObjectProperty.setRequired(request.getParameter("required"));
		aObjectProperty.setStored(request.getParameter("stored"));
		aObjectProperty.setIndexed(request.getParameter("indexed"));
		aObjectProperty.setTermVectors(request.getParameter("termVectors"));
		aObjectProperty.setWebListShow(request.getParameter("webListShow"));
		aObjectProperty.setWebDetailShow(request.getParameter("webDetailShow"));
		aObjectProperty.setAdminListShow(request.getParameter("adminListShow"));
		aObjectProperty.setAdminDetailShow(request.getParameter("adminDetailShow"));
		User logUser = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		Classes classes = publicService.findClasses(Integer.parseInt(classid));
		ObjectProperty bObjectProperty = new ObjectProperty();
		if (!id.equals("0")) {
			aObjectProperty.setId(Integer.parseInt(id));
			int logTime = 0;
			try {
				bObjectProperty = baseService.editObjectProperty(aObjectProperty);
			} catch (Exception e) {
				this.Log(
						logUser.getId(),
						"general_data",
						null,
						null,
						"【" + logUser.getNickname() + "】【修改】知识结构【"
								+ classes.getNameZh() + "】对象属性【" + nameZh
								+ "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(
						logUser.getId(),
						"general_data",
						null,
						null,
						"【" + logUser.getNickname() + "】【修改】知识结构【"
								+ classes.getNameZh() + "】对象属性【" + nameZh
								+ "】成功！", 0);
			}
		} else {
			int logTime = 0;
			try {
				bObjectProperty = baseService.saveObjectProperty(aObjectProperty);
			} catch (Exception e) {
				this.Log(
						logUser.getId(),
						"general_data",
						null,
						null,
						"【" + logUser.getNickname() + "】【新增】知识结构【"
								+ classes.getNameZh() + "】对象属性【" + nameZh
								+ "】失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.Log(
						logUser.getId(),
						"general_data",
						null,
						null,
						"【" + logUser.getNickname() + "】【新增】知识结构【"
								+ classes.getNameZh() + "】对象属性【" + nameZh
								+ "】成功！", 0);
			}

		}
		// String result = formatToJson(DataProperty2);
		String result = "{\"result\":" + "\"ok\"}";

		dynamicService.saveObjectForCache();
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 查询ObjectProperty
	@RequestMapping("KnowledgeObjectPropertyList")
	public void toKnowledgeObjectPropertyList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("lid");
		Classes Classes1 = publicService.findClasses(Integer.parseInt(id));
		List<ObjectProperty> list1 = publicService.getObjectProperty(Classes1);
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		for (int i = 0; i < list1.size(); i++) {
			ObjectProperty aObjectProperty = list1.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", aObjectProperty.getId());
			mp.put("name", aObjectProperty.getNameZh());
			mp.put("nameen", aObjectProperty.getNameEn());
			r.add(mp);
		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 修改DataProperty
	@RequestMapping("KnowledgeObjectPropertyedit")
	public void toKnowledgeObjectPropertyedit(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		ObjectProperty aObjectProperty = publicService.findObjectProperty(Integer.parseInt(id));
		CommonObjectProperty aCommonObjectProperty = null;
		Map<String,Object> map = new HashMap<String, Object>();
		if (aObjectProperty.getCommonObjectPropertyId() != 0) {
			aCommonObjectProperty = publicService.findCommonObjectProperty(aObjectProperty.getCommonObjectPropertyId());
			map.put("commonObjectProperty", aCommonObjectProperty);
			//aObjectProperty.setCommonObjectProperty(aCommonObjectProperty);
		} else {
			map.put("commonObjectProperty", null);
		}

		String Fieldsstring = aObjectProperty.getRelevanceClassFields();
		if (!Fieldsstring.equals("0")) {
			String string2[] = Fieldsstring.split(",");
			DataProperty aDataProperty[] = new DataProperty[string2.length];
			for (int i = 0; i < string2.length; i++) {
				aDataProperty[i] = publicService.findDataProperty(Integer.parseInt(string2[i]));
			}
			//aObjectProperty.setDataProperty(aDataProperty);
			map.put("dataProperty", aDataProperty);
		}
		map.put("text", aObjectProperty);
		String result = formatToJson(map);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 删除ObjectProperty数据
	@RequestMapping("KnowledgeObjectPropertyydel")
	public void toKnowledgeObjectPropertydel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		ObjectProperty aObjectProperty = new ObjectProperty();
		// DataProperty1.setId(Integer.parseInt(id));
		aObjectProperty = publicService
				.findObjectProperty(Integer.parseInt(id));
		int logTime = 0;
		User logUser = publicService.findUser((Integer) request.getSession()
				.getAttribute("userid"));
		Classes classes = publicService.findClasses(aObjectProperty
				.getClassesId());
		try {
			baseService.deleteObjectProperty(aObjectProperty);
		} catch (Exception e) {
			this.Log(
					logUser.getId(),
					"general_data",
					null,
					null,
					"【" + logUser.getNickname() + "】【删除】知识结构【"
							+ classes.getNameZh() + "】对象属性【"
							+ aObjectProperty.getNameZh() + "】失败！请检查数据是否正确！", 1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.Log(
					logUser.getId(),
					"general_data",
					null,
					null,
					"【" + logUser.getNickname() + "】【删除】知识结构【"
							+ classes.getNameZh() + "】对象属性【"
							+ aObjectProperty.getNameZh() + "】成功！", 0);
		}

		dynamicService.saveObjectForCache();
		String result = "{\"result\":" + "\"ok\"}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	/*
	 * 导入导出功能管理
	 */
	// 数据导入列表
	@RequestMapping("data-import-list.html")
	public String toDataImportList() {

		return "/modules/knowledgedata/data_import_list";
	}

	// 新建导入列表
	@RequestMapping("data-import-from.html")
	public String toDataImportFrom() {

		return "/modules/knowledgedata/data_import_from";
	}

	// 新建数据源列表
	@RequestMapping("data-import-source-from.html")
	public String toDataImportSourceFrom() {

		return "/modules/knowledgedata/data_import_source_list";
	}

	/*
	 * 导入导出功能管理
	 */
	// 数据导入检索查询
	@RequestMapping("KnowledgeImportList")
	@ResponseBody
	public void toKnowledgeImportList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = Integer.parseInt(request
				.getParameter("pageNumber"));
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if(text !=null && !"".equals(text)){
			queryParams.put("%,"+queryParam, text);
		}
		List<DataImport> list = publicService.getDataImport(queryParams,pageSize, pageNumber);
		List<DataSource> dataSource =publicService.getDataSource();
		List<Classes> classes =publicService.getClasses();
		long count = publicService.getDataImportCount(queryParams);
		/*for (int i = 0; i < list.size(); i++) {
			DataImport aDataImport = list.get(i);
			//DataSource aDataSource = publicService.findDataSource(aDataImport.getDataSourceId());
			//list.get(i).setDataSource(aDataSource);
			//Classes aClasses = publicService.findClasses(aDataImport.getClassesId());
			//list.get(i).setClasses(aClasses);
		}*/
		String result = formatToJson(list);
		String rdataSource = formatToJson(dataSource);
		String rclasses = formatToJson(classes);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result + ",");
		sb.append("\"rdataSource\":" + rdataSource + ",");
		sb.append("\"rclasses\":" + rclasses);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}

	// 数据导入保存
	@RequestMapping("KnowledgeImportsave")
	public void toKnowledgeImportsave(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String dataSourceId = request.getParameter("dataSourceId");
		String classesId = request.getParameter("classesId");
		String description = request.getParameter("description");
		String path = request.getParameter("path");
		//获取服务器地址
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		if(path != null && !"".equals(path)){
			path = path.replaceAll(uploadPath, "");
		}
		// Integer sort = Integer.parseInt(request.getParameter("status"));
		DataImport aDataImport = new DataImport();
		aDataImport.setName(name);
		aDataImport.setFilePath(path);
		aDataImport.setDescription(description);
		aDataImport.setClassesId(Integer.parseInt(classesId));
		aDataImport.setDataSourceId(Integer.parseInt(dataSourceId));
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = sdf.format(new java.util.Date());
		aDataImport.setCreateTime(date);
		Integer departmentid = (Integer) request.getSession().getAttribute(
				"departmentid");
		aDataImport.setStatus(0);
		aDataImport.setCreateUserId(departmentid);
		DataImport bDataImport = new DataImport();
		bDataImport = baseService.saveDataImport(aDataImport);
		String result = formatToJson(bDataImport);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 数据导入{导入数据处理}
	@RequestMapping("KnowledgeImportHandle")
	public void toKnowledgeImportHandle(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataImport aDataImport = publicService.findDataImport(Integer.parseInt(id));
		Classes aClasses = publicService.findClasses(aDataImport.getClassesId());
		List<DataProperty> dataProperties = searchService.getDataPropertyListCache(aClasses.getNameEn());

		List<DataProperty> dataPropertiesList = new ArrayList<DataProperty>();
		for (int i = 0; i < dataProperties.size(); i++) {
			DataProperty dataProperty = dataProperties.get(i);
			if (dataProperty.getDictId() != 0) {
				dataPropertiesList.add(dataProperty);
			}
		}

		//String path = "D://root";
		String path =  XxlConfClient.get("dal.file.path", "");
		path += aDataImport.getFilePath();
		boolean falg = true;
		String kk = "";
		int i1 = 2;
		List<HashMap<String, Object>> list = DBUtils.readExcel(path);
		/*
		 * for (Map<String, Object> m : list) {
		 * 
		 * //HashMap<String, Object> data = new HashMap<String, Object>(); for
		 * (String k : m.keySet()) {
		 * 
		 * for(int i=0;i<dataPropertiesList.size();i++){ DataProperty
		 * aDataProperty=dataPropertiesList.get(i); boolean falg2=false;
		 * if(aDataProperty
		 * .getDictId()!=0&&k.equals(aDataProperty.getNameEn())){ Dict
		 * aDict=publicService.findDict(aDataProperty.getDictId());
		 * List<DictItem> DictItemlist=publicService.getDictItem(aDict); for(int
		 * j=0;j<DictItemlist.size();j++){ DictItem
		 * aDictItem=DictItemlist.get(j);
		 * if(aDictItem.getValue().equals(m.get(k))){ falg2=true; break; }
		 * if(m.get(k).equals("")||m.get(k) == null){ falg2=true; } }
		 * if(!falg2){ falg=false; kk=k+"字段的值不能为"+m.get(k); break; } }
		 * 
		 * } if(!falg) { break; }
		 * 
		 * } if(!falg) { break; } i1++; }
		 */
		String result;
		// System.out.println(i1+"  "+kk+falg);
		if (falg) {
			List<Map<String,Object>> dynamicData = null;
			HashMap<String, Object> xmConditions =null;
			HashMap<String, Object> sjConditions =null;
			for (Map<String, Object> m : list) {
				int xmJudge = 0;
				int sjJudge = 0;
				dynamicData = new ArrayList<Map<String,Object>>();
				if (aClasses.getNameEn().equals("ke_hu_zi_liao")) {
					xmConditions = new HashMap<String, Object>();
					xmConditions.put("=xing_ming", m.get("xing_ming"));
					xmJudge = dynamicService.getDynamicCount(aClasses.getNameEn(), xmConditions).intValue();
					if(m.get("shou_ji") != null && !"".equals(m.get("shou_ji"))){
						sjConditions = new LinkedHashMap<String, Object>();
						sjConditions.put("=shou_ji", m.get("shou_ji"));
						sjJudge = dynamicService.getDynamicCount(aClasses.getNameEn(), sjConditions).intValue();
					}
				}
				HashMap<String, Object> data = new HashMap<String, Object>();
				if(xmJudge == 0 && sjJudge == 0){
					for (String k : m.keySet()) {
						if (!k.equals("username")) {
							data.put(k, m.get(k));
						}
					}
				}

				String status = "0";
				String version = "1.0";
				String createTime = DateUtils.getDateTime();
				String dataSource = "1";
				/* 筛选用户 */
				Integer userid = 0;
				HashMap<String, Object> queryParams = new HashMap<String, Object>();
				if(m.get("username") != null && !"".equals(m.get("username"))){
					queryParams.put("=,username", m.get("username"));
					int userLong = publicService.getUserCount(queryParams).intValue();
					List<User> userList = publicService.getUser(queryParams, 1,userLong);
					if (userList.size() > 0) {
						for (int i = 0; i < userList.size(); i++) {
							User user = userList.get(i);
							if (user.getUsername().equals(m.get("username"))) {
								userid = user.getId();
								break;
							}
						}
					} else {
						userid = (Integer) request.getSession().getAttribute("userid");
					}
				}else {
					if(m.get("create_user_id") != null && !"".equals(m.get("create_user_id"))&& !" ".equals(m.get("create_user_id"))){
						userid = Integer.parseInt(m.get("create_user_id").toString());
					}else{
						userid = (Integer) request.getSession().getAttribute("userid");
					}
				}
				if (xmJudge == 0 && sjJudge == 0) {
					//是否启用工作流
					Workflow workflow = null;
					WorkflowNode workflowNode = null;
					HashMap<String, Object> queryWorkflowParams = new HashMap<String, Object>();
					queryWorkflowParams.put("=,classes_en",aClasses.getNameEn());
					List<Workflow> workflowList = publicService.getWorkflow(queryWorkflowParams, 1, 1);
					if(null != workflowList && workflowList.size()>0){
						workflow = workflowList.get(0);
						if(workflow.getStatus() == 1){
							status = "-1";
							HashMap<String, Object> queryWorkflowNodeParams = new HashMap<String, Object>();
							queryWorkflowNodeParams.put("=,workflow_id", workflow.getId());
							queryWorkflowNodeParams.put("=,sort", 1);
							List<WorkflowNode> workflowNodeList = publicService.getWorkflowNode(queryWorkflowNodeParams, 1, 1);
							if(null != workflowNodeList && workflowNodeList.size()>0){
								workflowNode = workflowNodeList.get(0);
								HashMap<String, Object> queryUserParams = new HashMap<String, Object>();
								queryUserParams.put("=,username", workflowNode.getExecutor());
								List<User> userList= publicService.getUser(queryUserParams, 1, 1);
								if(null != userList && userList.size()>0){
									data.put("submit_user_id", userList.get(0).getId());
								}
							}
						}
					}
					dynamicService.addDynamicData(aClasses.getNameEn(), data,createTime,userid.toString(), status, version,
							aClasses.getId().toString(), dataSource);
				}

			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String date = sdf.format(new java.util.Date());
			aDataImport.setCreateTime(date);
			aDataImport.setStatus(1);
			baseService.editDataImport(aDataImport);

			result = "{\"result\":" + "\"ok\"}";
		} else {
			result = "{\"result\":" + "\"第" + i1 + "行字段名称为" + kk + "\"" + "}";
		}
		// System.out.println(result);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 导入数据删除
	@RequestMapping("KnowledgeImportdel")
	public void toKnowledgeImportdel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataImport aDataImport = new DataImport();
		aDataImport = publicService.findDataImport(Integer.parseInt(id));
		baseService.deleteDataImport(aDataImport);
		// baseService.saveObjectForCache();
		String result = "{\"result\":" + "\"ok\"}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 数据导出列表
	@RequestMapping("data-export-from.html")
	public String toDataExportfrom() {

		return "/modules/knowledgedata/data_export_from";
	}
	// 数据导出用户
	@RequestMapping("exportUser")
	public void exportUser(HttpServletRequest request,HttpServletResponse response) throws Exception {
		String result = formatToJson(publicService.getUser());
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	// 数据导出保存
	@RequestMapping("KnowledgeExportsave")
	public void toKnowledgeExportsave(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String dataSourceId = request.getParameter("dataSourceId");
		String classesId = request.getParameter("classesId");
		String description = request.getParameter("description");
		//勾选内容
		String[] selectIds =request.getParameterValues("value");
		// Integer sort = Integer.parseInt(request.getParameter("status"));
		String userIds="";
		for (int i = 0; i < selectIds.length; i++) {
			userIds += selectIds[i]+";";
		}
		if(userIds!= null && !"".equals(userIds)){
			userIds=userIds.substring(0, userIds.length()-1);
		}
		DataExport aDataExport = new DataExport();
		aDataExport.setName(name);
		aDataExport.setDescription(description);
		aDataExport.setClassesId(Integer.parseInt(classesId));
		aDataExport.setDataSourceId(Integer.parseInt(dataSourceId));
		aDataExport.setUserIds(userIds);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = sdf.format(new java.util.Date());
		aDataExport.setCreateTime(date);
		aDataExport.setStatus(0);
		Integer departmentid = (Integer) request.getSession().getAttribute("departmentid");
		aDataExport.setCreateUserId(departmentid);
		DataExport bDataExport = new DataExport();
		bDataExport = baseService.saveDataExport(aDataExport);
		String result = formatToJson(bDataExport);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 数据导出检索查询
	@RequestMapping("KnowledgeExportList")
	@ResponseBody
	public void toKnowledgeExportList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = Integer.parseInt(request
				.getParameter("pageNumber"));
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if(text != null && !"".equals(text)){
			queryParams.put("%,"+queryParam, text);
		}
		List<DataExport> list = publicService.getDataExport(queryParams,pageSize, pageNumber);
		long count = publicService.getDataExportCount(queryParams);
		List<DataSource> dataSource =publicService.getDataSource();
		List<Classes> classes =publicService.getClasses();
		/*for (int i = 0; i < list.size(); i++) {
			DataExport aDataExport = list.get(i);
			DataSource aDataSource = publicService.findDataSource(aDataExport.getDataSourceId());
			list.get(i).setDataSource(aDataSource);
			Classes aClasses = publicService.findClasses(aDataExport.getClassesId());
			list.get(i).setClasses(aClasses);
		}*/
		String result = formatToJson(list);
		String rdataSource = formatToJson(dataSource);
		String rclasses = formatToJson(classes);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result + ",");
		sb.append("\"rdataSource\":" + rdataSource + ",");
		sb.append("\"rclasses\":" + rclasses);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}

	// 数据导出列表
	@RequestMapping("data-export-list.html")
	public String toDataExportList() {

		return "/modules/knowledgedata/data_export_list";
	}

	// 导出数据删除
	@RequestMapping("KnowledgeExportdel")
	public void toKnowledgeExportdel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		DataExport aDataExport = new DataExport();
		aDataExport = publicService.findDataExport(Integer.parseInt(id));
		baseService.deleteDataExport(aDataExport);
		// baseService.saveObjectForCache();
		String result = "{\"result\":" + "\"ok\"}";
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 数据导出下载
	@RequestMapping("DataExportdownload")
	public void Exportdownload(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");

		String id = request.getParameter("downloadid");
		DataExport aDataExport = new DataExport();
		aDataExport = publicService.findDataExport(Integer.parseInt(id));
		Classes Classes1 = publicService.findClasses(aDataExport.getClassesId());
		String fileName = Classes1.getNameEn() + ".xls";
		String path = request.getSession().getServletContext().getRealPath("/")
				+ "/upload/download/";

		toExportkk(id, path);
		downloadkk(request, response, fileName, path);

	}

	// 数据下载处理
	public void toExportkk(String id, String path) {
		DataExport aDataExport = new DataExport();
		aDataExport = publicService.findDataExport(Integer.parseInt(id));
		Classes Classes1 = publicService.findClasses(aDataExport.getClassesId());
		List<DataProperty> list1 = publicService.getDataProperty(Classes1);
		List<HashMap<String, Object>> list2 = new ArrayList<HashMap<String, Object>>();
		List<Map<String, Object>> list= new ArrayList<Map<String,Object>>();
		Map<String,Object> conditions = null;
		String userIds = aDataExport.getUserIds();
		if(userIds != null && !"".equals(userIds)){
			String users [] = userIds.split(";");
			for (int i = 0; i < users.length; i++) {
				conditions = new LinkedHashMap<String, Object>();
				conditions.put("=create_user_id", users[i]);
				Long along = dynamicService.getDynamicCount(Classes1.getNameEn(), conditions);
				List<Map<String, Object>> DynamicDataList = dynamicService.getDynamicData(Classes1.getNameEn(), conditions, 1,along.intValue());
				for (int j = 0; j < DynamicDataList.size(); j++) {
					list.add(DynamicDataList.get(j));
				}
			}
		}
		// 标题
		for (Map<String, Object> m : list) {
			LinkedHashMap<String, Object> map2 = new LinkedHashMap<String, Object>();
			for(int j =0;j<list1.size();j++){
				DataProperty dataProperty =list1.get(j);
				String k=dataProperty.getNameEn();
			//for (String k : m.keySet()) {
				if (k.equals("createTime")) {
					map2.put(k, "创建时间");
				} else if (k.equals("dataSource")) {
					map2.put(k, "数据来源");
				} else if (k.equals("updateTime")) {
					map2.put(k, "更新时间");
				} else if (k.equals("status")) {
					map2.put(k, "状态");
				} else if (k.equals("submitTime")) {
					map2.put(k, "提交时间");
				} else if (k.equals("version")) {
					map2.put(k, "版本号");
				} else if (k.equals("id")) {
					map2.put(k, "唯一主键");
				} else if (k.equals("updateUserId")) {
					map2.put(k, "更新部门");
				} else if (k.equals("classesId")) {
					map2.put(k, "表名");
				} else if (k.equals("submitUserId")) {
					map2.put(k, "提交部门");
				} else if (k.equals("createUserId")) {
					map2.put(k, "创建部门");
				} else {
					String name1 = " ";
					for (int i = 0; i < list1.size(); i++) {
						DataProperty DataProperty1 = list1.get(i);
						if (k.equals(DataProperty1.getNameEn())) {
							name1 = DataProperty1.getNameZh();
							break;
						}
					}
					// System.out.println(name1);
					map2.put(k, name1);
				}

			}
			list2.add(map2);
			break;
		}

		// 内容
		for (Map<String, Object> m : list) {
			LinkedHashMap<String, Object> map2 = new LinkedHashMap<String, Object>();
//			for (String k : m.keySet()) {
			for(int r =0;r<list1.size();r++){
				DataProperty dataProperty =list1.get(r);
				String k=dataProperty.getNameEn();
				if (m.get(k) == null) {
					map2.put(k, " ");
				} else {
					String name = null;
					// 字段判断
					for (int i = 0; i < list1.size(); i++) {
						DataProperty DataProperty1 = list1.get(i);
						if (DataProperty1.getNameEn().equals(k)) {
							if (DataProperty1.getDataTypeId() == 7) {
								Dict aDict = null;
								aDict = publicService.findDict(DataProperty1
										.getDictId());
								if (aDict != null) {
									List<DictItem> aDictItem;
									aDictItem = publicService
											.getDictItem(aDict);
									for (int j = 0; j < aDictItem.size(); j++) {
										if (m.get(k).equals(
												aDictItem.get(j).getValue())) {
											name = aDictItem.get(j).getNameZh();
										}
									}
								}

							}
						}
						// 用户名判断
						if (k.equals("classesId")) {
							name = Classes1.getNameZh();
						} else if (k.equals("createUserId")
								|| k.equals("submitUserId")
								|| k.equals("updateUserId")) {
							// Department aDepartment=new Department();
							// aDepartment=publicService.findDepartment(Integer.parseInt(m.get(k).toString()));
							// name=aDepartment.getName();
							name = m.get(k).toString();
						}

						if (name != null) {
							map2.put(k, name);
						} else {
							map2.put(k, m.get(k));
						}

					}
				}
			}
			list2.add(map2);
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = sdf.format(new java.util.Date());
		aDataExport.setCreateTime(date);
		baseService.editDataExport(aDataExport);
		DBUtils.writeExcel(path + Classes1.getNameEn() + ".xls", list2, 1);
	}

	// 工具类 导出（处理）
	public List<HashMap<String, Object>> toexport(List<DataProperty> list1) {

		List<HashMap<String, Object>> list2 = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> map2 = new LinkedHashMap<String, Object>();
		for (int i = 0; i < list1.size(); i++) {
			DataProperty DataProperty1 = list1.get(i);
			if (DataProperty1.getDataTypeId() != null && DataProperty1.getDataTypeId() != 0) {
				DataType dataType =publicService.findDataType(DataProperty1.getDataTypeId());
				String test = dataType.getNameEn();
				if (test.equals("upload_pic_single")
						|| test.equals("upload_pic_multiple")
						|| test.equals("upload_file_single")
						|| test.equals("upload_file_multiple")) {
				} else if (test.equals("select_single")) {
					// 单选处理
				} else if (test.equals("select_multiple")) {
					// 多选处理
				} else {
					// 文本数值处理
					map2.put(DataProperty1.getNameZh(),
							DataProperty1.getNameZh());
				}
			}
		}
		list2.add(map2);
		return list2;
		// DBUtils.writeExcel(path+"\\"+id+".xls",list2,0);
	}

	// 模板导出-数据导入模板列表
	@RequestMapping("data-import-templet-list.html")
	public String toDataImporttempletList() {

		return "/modules/knowledgedata/data_import_templet_list";
	}

	// 模板下载
	@RequestMapping("DataImportTempletdownload")
	public void download(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		String id = request.getParameter("downloadid");
		String downtype = request.getParameter("downdd");

		Classes Classes1 = publicService.findClasses(Integer.parseInt(id));
		String fileName = Classes1.getNameEn() + ".xls";
		String path = request.getSession().getServletContext().getRealPath("/")
				+ "/upload/template/";
		tokk(Classes1, path, downtype);
		downloadkk(request, response, fileName, path);

	}

	// 工具类 生成模板
	public void tokk(Classes Classes1, String path, String downtype) {
		List<DataProperty> list1 = publicService.getDataProperty(Classes1);
		List<HashMap<String, Object>> list2 = new ArrayList<HashMap<String, Object>>();
		String kk = Classes1.getNameEn();
		Integer aInteger = Integer.parseInt(downtype);
		if (aInteger == 1) {
			LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
			for (int i = 0; i < list1.size(); i++) {
				DataProperty DataProperty1 = list1.get(i);
				if (DataProperty1.getDataTypeId() == 2
						|| DataProperty1.getDataTypeId() == 3
						|| DataProperty1.getDataTypeId() == 4) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				} else if (DataProperty1.getDataTypeId() == 5
						|| DataProperty1.getDataTypeId() == 6
						|| DataProperty1.getDataTypeId() == 8) {

				} else if (DataProperty1.getDataTypeId() == 7) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				} else if (DataProperty1.getDataTypeId() == 9) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				} else if (DataProperty1.getDataTypeId() == 10) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				} else if (DataProperty1.getDataTypeId() == 11) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				} else if (DataProperty1.getDataTypeId() == 12) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				} else if (DataProperty1.getDataTypeId() == 13) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				} else if (DataProperty1.getDataTypeId() == 20) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				} else if (DataProperty1.getDataTypeId() == 21) {
					map.put(DataProperty1.getNameEn(),
							DataProperty1.getNameZh());
				}

			}
			list2.add(map);

		}
		LinkedHashMap<String, Object> map2 = new LinkedHashMap<String, Object>();
		for (int i = 0; i < list1.size(); i++) {
			DataProperty DataProperty1 = list1.get(i);
			if (DataProperty1.getDataTypeId() == 2
					|| DataProperty1.getDataTypeId() == 3
					|| DataProperty1.getDataTypeId() == 4) {
				map2.put(DataProperty1.getNameEn(), "字符串");
			} else if (DataProperty1.getDataTypeId() == 5
					|| DataProperty1.getDataTypeId() == 6
					|| DataProperty1.getDataTypeId() == 8) {

			} else if (DataProperty1.getDataTypeId() == 7) {
				String Dictname = "";
				if (DataProperty1.getDictId() != null) {
					Dict aDict = publicService.findDict(DataProperty1
							.getDictId());

					List<DictItem> alist = publicService.getDictItem(aDict);
					for (int k = 0; k < alist.size(); k++) {
						Dictname += alist.get(k).getNameZh() + "："
								+ alist.get(k).getValue() + "，";
					}
					// System.out.println(Dictname);
				}
				map2.put(DataProperty1.getNameEn(), Dictname);

			} else if (DataProperty1.getDataTypeId() == 9) {
				map2.put(DataProperty1.getNameEn(), "数值");
			} else if (DataProperty1.getDataTypeId() == 10) {
				map2.put(DataProperty1.getNameEn(), "2015");
			} else if (DataProperty1.getDataTypeId() == 11) {
				map2.put(DataProperty1.getNameEn(), "2016-09");
			} else if (DataProperty1.getDataTypeId() == 12) {
				map2.put(DataProperty1.getNameEn(), "2016-09-20");
			} else if (DataProperty1.getDataTypeId() == 13) {
				map2.put(DataProperty1.getNameEn(), "2016-09-21 14:06:27");
			}else if (DataProperty1.getDataTypeId() == 20) {
				map2.put(DataProperty1.getNameEn(), "字符串");
			}
		}
		map2.put("username", "字符串");
		list2.add(map2);
		DBUtils.writeExcel(path + kk + ".xls", list2, aInteger);
	}

	// 上传excel导入
	@RequestMapping("knowledgeuploading")
	public void toKnowledgeEditDataClassDetailUpload(
			HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		// 上传附件
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		MultipartFile file = multipartRequest.getFile("uploadify");
		// 获取服务器地址
		ServletContext sc = request.getSession().getServletContext();
		// 附件存放服务器路径
		String dir = "";
		String fileName = file.getOriginalFilename();
		Long _l = System.nanoTime();
		String _extName = fileName.substring(fileName.indexOf("."));
		dir = sc.getRealPath("/upload/upload/");
		if (!new File(dir).exists()) {
			new File(dir).mkdirs();
		}
		fileName = _l + _extName;
		String uploadPath = "/upload/upload/" + fileName;
		String responseStr = "";
		try {
			FileUtils.writeByteArrayToFile(new File(dir, fileName),
					file.getBytes());// 服务器中生成文件
			responseStr = fileName;
		} catch (IOException e) {
			e.printStackTrace();
			responseStr = "上传失败";
		}
		response.getWriter().print(uploadPath);
	}

	// 跳转数据数据集查询页面。
	@RequestMapping("knowledgeData-Register-list.html")
	public String toKnowledgedataRegisterlist(HttpServletResponse response)
			throws IOException {

		return "/modules/knowledgedata/knowledge_data_Register_list";
	}

	// 跳转数据数据集添加页面。
	@RequestMapping("knowledge-data-Register-from.html")
	public String toKnowledgedataRegisterfrom(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "/modules/knowledgedata/knowledge_data_Register_from";
	}

	// 查询所有的管理员类型，提供下拉选择。
	@RequestMapping("Knowledgeadminall")
	public void toKnowledgeadminall(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<Department> list1 = publicService.getDepartment();
		for (int i = 0; i < list1.size(); i++) {
			Department aDepartment = new Department();
			aDepartment = list1.get(i);
			if (aDepartment.getId() == 14) {
				list1.remove(i);
			}

		}
		String result = formatToJson(list1);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 查询所有菜单管理的Classes
	@RequestMapping("KnowledgemenuListall")
	public void toKnowledgemenuListall(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer userid = (Integer) request.getSession().getAttribute("userid");
		List<UserRole> aUserRole = publicService.getUserRole();
		String temp1 = "";
		for (int i = 0; i < aUserRole.size(); i++) {
			UserRole bUserRole = aUserRole.get(i);
			if (bUserRole.getUserId().equals(userid)) {
				List<Permission> aPermission = publicService.getPermission();
				for (int j = 0; j < aPermission.size(); j++) {
					Permission bPermission = aPermission.get(j);
					if (bUserRole.getRoleId().equals(bPermission.getRoleId())) {
						temp1 += bPermission.getMenuIds() + ",";
					}
				}
			}
		}
		ArrayList list2 = new ArrayList();
		if (!"".equals(temp1)) {
			temp1 = temp1.substring(0, temp1.length() - 1);
			String[] temp = temp1.split(",");

			for (int i = 0; i < temp.length; i++) {
				if (!list2.contains(temp[i]))
					list2.add(temp[i]);
			}
		}
		List<Menu> list1 = publicService.getMenu();
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		for (int i = 0; i < list1.size(); i++) {
			Menu aMenu = list1.get(i);
			boolean flag = false;
			for (int j = 0; j < list2.size(); j++) {

				if (list2.get(j).equals(aMenu.getId().toString())) {
					flag = true;
					break;
				}
			}
			if (flag) {
				mp = new LinkedHashMap<String, Object>();
				mp.put("id", aMenu.getId());
				mp.put("url", aMenu.getUrl());
				mp.put("name", aMenu.getName());
				mp.put("icon", aMenu.getIcon());
				mp.put("pId", aMenu.getParentId());
				r.add(mp);
			}
		}
		LinkedHashMap<String, Object> mp2 = null;
		mp2 = new LinkedHashMap<String, Object>();
		mp2.put("id", 0);
		mp2.put("name", "123");
		mp2.put("url", "123");
		mp2.put("icon", "123");
		mp2.put("pId", 999999);
		String result = TreeJsion.get(mp2, r);
		// System.out.println(r);
		// System.out.println(result);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	public void downloadkk(HttpServletRequest request,
			HttpServletResponse response, String fileName, String path)
			throws Exception {
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		response.setHeader("Content-Disposition", "attachment;fileName="
				+ fileName);
		try {
			// 这个download目录为啥建立在classes下的
			InputStream inputStream = new FileInputStream(new File(path + "/"
					+ File.separator + fileName));
			OutputStream os = response.getOutputStream();
			byte[] b = new byte[2048];
			int length;
			while ((length = inputStream.read(b)) > 0) {
				os.write(b, 0, length);
			}
			// 这里主要关闭。
			os.close();
			inputStream.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	// 跳转数据类型导出。
	@RequestMapping("knowledge-Classes-class-export.html")
	public String toknowledgeClassesClassRxport(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		return "/modules/knowledgedata/knowledge_Classes_class_export";
	}

	//知识结构管理 -- 导出Class
	@RequestMapping("classExportdownload")
	public void toClassExportdownload(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String menuids = request.getParameter("menuids");
		String[] classesIds = menuids.split(",");
		DocumentBuilderFactory fct = DocumentBuilderFactory.newInstance();
		DocumentBuilder bui;
		try {
			// 驱动
			bui = fct.newDocumentBuilder();
			// 创建对象
			Document doc = bui.newDocument();
			// 设置根目录
			Element KnData = doc.createElement("KnData");

			// Long count = publicService.getClassesCount(null);
			// Integer cont1=Integer.parseInt(count.toString());
			// System.out.println(cont1);
			// List<Classes> claList = publicService.getClasses(null, 1, cont1);
			// <!-- 知识结构-类 -->
			// 设置二级目录
			Element KnClasses = doc.createElement("KnClasses");
			for (int i = 0; i < classesIds.length; i++) {
				Classes cs = publicService.findClasses(Integer
						.parseInt(classesIds[i]));
				// 创建三级目录
				Element Classes = doc.createElement("Classes");
				// 二级标题属性
				Attr id = doc.createAttribute("id");
				// 赋值
				id.setNodeValue(cs.getId().toString());
				// 写入二级目录
				Classes.setAttributeNode(id);
				Attr classesId = doc.createAttribute("classesId");
				classesId.setNodeValue(cs.getClassesId().toString());
				Classes.setAttributeNode(classesId);
				// 创建节点
				Element nameEn = doc.createElement("nameEn");
				// 赋值
				nameEn.setTextContent(cs.getNameEn());

				Element nameZh = doc.createElement("nameZh");
				nameZh.setTextContent(cs.getNameZh());

				Element description = doc.createElement("description");
				description.setTextContent(cs.getDescription());

				Element display = doc.createElement("display");
				display.setTextContent(String.valueOf(cs.getDisplay()));

				Element sort = doc.createElement("sort");
				sort.setTextContent(cs.getSort().toString());

				// 将节点写入二级目录
				Classes.appendChild(nameEn);
				Classes.appendChild(nameZh);
				Classes.appendChild(description);
				Classes.appendChild(display);
				Classes.appendChild(sort);

				// 写入上级目录
				KnClasses.appendChild(Classes);

				// 写入上级目录
				KnData.appendChild(KnClasses);

				// 查询classesids
				List<DataProperty> lists = publicService.getDataProperty(cs);
				// 设置二级目录
				Element KnDataProperty = doc.createElement("KnDataProperty");
				for (DataProperty dp : lists) {

					// 创建三级目录
					Element DataProperty = doc.createElement("DataProperty");
					// 二级标题属性
					Attr dataPropertyId = doc.createAttribute("id");
					// 赋值
					dataPropertyId.setNodeValue(dp.getId().toString());
					// 写入二级目录
					DataProperty.setAttributeNode(dataPropertyId);
					Attr dataPropertyClassesId = doc
							.createAttribute("classesId");
					dataPropertyClassesId.setNodeValue(dp.getClassesId()
							.toString());
					DataProperty.setAttributeNode(dataPropertyClassesId);
					// 创建节点
					Element dataPropertyNameEn = doc.createElement("nameEn");
					// 赋值
					dataPropertyNameEn.setTextContent(dp.getNameEn());

					Element dataPropertyNameZh = doc.createElement("nameZh");
					dataPropertyNameZh.setTextContent(dp.getNameZh());

					Element commonDataPropertyId = doc
							.createElement("commonDataPropertyId");
					commonDataPropertyId.setTextContent(dp
							.getCommonDataPropertyId().toString());

					Element dataTypeId = doc.createElement("dataTypeId");
					dataTypeId.setTextContent(dp.getDataTypeId().toString());

					Element separator = doc.createElement("separator");
					separator.setTextContent(dp.getSeparator());

					Element fieldLength = doc.createElement("fieldLength");
					fieldLength.setTextContent(dp.getFieldLength().toString());

					Element field = doc.createElement("field");
					field.setTextContent(dp.getField());

					Element solrIndexField = doc
							.createElement("solrIndexField");
					solrIndexField.setTextContent(dp.getSortField());

					Element dictId = doc.createElement("dictNameEn");
					if(dp.getDictId() != null && !"".equals(dp.getDictId()) && 0 != dp.getDictId()){
						dictId.setTextContent(publicService.findDict(dp.getDictId()).getNameEn());
					}

					Element multiValued = doc.createElement("multiValued");
					multiValued.setTextContent(String.valueOf(dp.getMultiValued()));

					Element required = doc.createElement("required");
					required.setTextContent(String.valueOf(dp.getRequired()));

					Element stored = doc.createElement("stored");
					stored.setTextContent(String.valueOf(dp.getStored()));

					Element indexed = doc.createElement("indexed");
					indexed.setTextContent(String.valueOf(dp.getIndexed()));

					Element termVectors = doc.createElement("termVectors");
					termVectors.setTextContent(String.valueOf(dp.getTermVectors()));

					Element faceted = doc.createElement("faceted");
					faceted.setTextContent(String.valueOf(dp.getFaceted()));

					Element sortField = doc.createElement("sortField");
					sortField.setTextContent(String.valueOf(dp.getSortField()));

					Element webListShow = doc.createElement("webListShow");
					webListShow.setTextContent(String.valueOf(dp.getWebListShow()));

					Element webDetailShow = doc.createElement("webDetailShow");
					webDetailShow.setTextContent(String.valueOf(dp.getWebDetailShow()));

					Element adminListShow = doc.createElement("adminListShow");
					adminListShow.setTextContent(String.valueOf(dp.getAdminListShow()));

					Element adminDetailShow = doc
							.createElement("adminDetailShow");
					adminDetailShow.setTextContent(String.valueOf(dp.getAdminDetailShow()));

					Element relevanceClassShowField = doc
							.createElement("relevanceClassShowField");
					relevanceClassShowField.setTextContent(String.valueOf(dp.getRelevanceClassShowField()));

					Element formValidationRegulation = doc
							.createElement("formValidationRegulation");
					formValidationRegulation.setTextContent(dp
							.getFormValidationRegulation());

					Element dataPropertysort = doc.createElement("sort");
					dataPropertysort.setTextContent(dp.getSort().toString());

					// 将节点写入二级目录
					DataProperty.appendChild(dataPropertyNameEn);
					DataProperty.appendChild(dataPropertyNameZh);
					DataProperty.appendChild(commonDataPropertyId);
					DataProperty.appendChild(dataTypeId);
					DataProperty.appendChild(separator);
					DataProperty.appendChild(fieldLength);
					DataProperty.appendChild(field);
					DataProperty.appendChild(solrIndexField);
					DataProperty.appendChild(dictId);
					DataProperty.appendChild(multiValued);
					DataProperty.appendChild(required);
					DataProperty.appendChild(stored);
					DataProperty.appendChild(indexed);
					DataProperty.appendChild(termVectors);
					DataProperty.appendChild(faceted);
					DataProperty.appendChild(sortField);
					DataProperty.appendChild(webListShow);
					DataProperty.appendChild(webDetailShow);
					DataProperty.appendChild(adminListShow);
					DataProperty.appendChild(adminDetailShow);
					DataProperty.appendChild(relevanceClassShowField);
					DataProperty.appendChild(formValidationRegulation);
					DataProperty.appendChild(dataPropertysort);

					// 写入上级目录
					KnDataProperty.appendChild(DataProperty);

				}
				// 写入上级目录
				KnData.appendChild(KnDataProperty);
				// }
				// <!-- 知识结构-对象属性 -->
				List<ObjectProperty> ObjectPropertyList = publicService
						.getObjectProperty(cs);
				// ObjectProperty objectProperty=new ObjectProperty();
				// if(objectProperty.getClassesId().equals(cs.getId())){
				// 设置二级目录
				Element KnObjectProperty = doc
						.createElement("KnObjectProperty");
				for (ObjectProperty op : ObjectPropertyList) {

					// 创建三级目录
					Element ObjectProperty = doc
							.createElement("ObjectProperty");
					// 二级标题属性
					Attr objectPropertyId = doc.createAttribute("id");
					// 赋值
					objectPropertyId.setNodeValue(op.getId().toString());
					// 写入二级目录
					ObjectProperty.setAttributeNode(objectPropertyId);
					Attr objectPropertyClassesId = doc.createAttribute("classesNameEn");
					objectPropertyClassesId.setNodeValue(publicService.findClasses(op.getClassesId()).getNameEn());
					ObjectProperty.setAttributeNode(objectPropertyClassesId);
					// 创建节点
					Element objectPropertyNameEn = doc.createElement("nameEn");
					// 赋值
					objectPropertyNameEn.setTextContent(op.getNameEn());

					Element objectPropertyNameZh = doc.createElement("nameZh");
					objectPropertyNameZh.setTextContent(op.getNameZh());

					Element commonObjectPropertyId = doc
							.createElement("commonObjectPropertyId");
					commonObjectPropertyId.setTextContent(op
							.getCommonObjectPropertyId().toString());

					Element relevanceClassesId = doc
							.createElement("relevanceClassesId");
					relevanceClassesId.setTextContent(op
							.getRelevanceClassesId().toString());

					Element relevanceClassFields = doc
							.createElement("relevanceClassFields");
					relevanceClassFields.setTextContent(op
							.getRelevanceClassFields());

					Element objectPropertyField = doc.createElement("field");
					objectPropertyField.setTextContent(op.getField());

					Element objectPropertyMultiValued = doc
							.createElement("multiValued");
					objectPropertyMultiValued.setTextContent(String.valueOf(op
							.getMultiValued()));

					Element objectPropertyRequired = doc
							.createElement("required");
					objectPropertyRequired.setTextContent(String.valueOf(op
							.getRequired()));

					Element objectPropertyStored = doc.createElement("stored");
					objectPropertyStored.setTextContent(String.valueOf(op
							.getStored()));

					Element objectPropertyIndexed = doc
							.createElement("indexed");
					objectPropertyIndexed.setTextContent(String.valueOf(op
							.getIndexed()));

					Element objectPropertyTermVectors = doc
							.createElement("termVectors");
					objectPropertyTermVectors.setTextContent(String.valueOf(op
							.getTermVectors()));

					Element objectPropertyWebListShow = doc
							.createElement("webListShow");
					objectPropertyWebListShow.setTextContent(String.valueOf(op
							.getWebListShow()));

					Element objectPropertyWebDetailShow = doc
							.createElement("webDetailShow");
					objectPropertyWebDetailShow.setTextContent(String
							.valueOf(op.getWebDetailShow()));

					Element objectPropertyAdminListShow = doc
							.createElement("adminListShow");
					objectPropertyAdminListShow.setTextContent(String
							.valueOf(op.getAdminListShow()));

					Element objectPropertyAdminDetailShow = doc
							.createElement("adminDetailShow");
					objectPropertyAdminDetailShow.setTextContent(String
							.valueOf(op.getAdminDetailShow()));

					Element objectPropertySort = doc.createElement("sort");
					objectPropertySort.setTextContent(op.getSort().toString());

					// 将节点写入二级目录
					ObjectProperty.appendChild(objectPropertyNameEn);
					ObjectProperty.appendChild(objectPropertyNameZh);
					ObjectProperty.appendChild(commonObjectPropertyId);
					ObjectProperty.appendChild(relevanceClassesId);
					ObjectProperty.appendChild(relevanceClassFields);
					ObjectProperty.appendChild(objectPropertyField);
					ObjectProperty.appendChild(objectPropertyMultiValued);
					ObjectProperty.appendChild(objectPropertyRequired);
					ObjectProperty.appendChild(objectPropertyStored);
					ObjectProperty.appendChild(objectPropertyIndexed);
					ObjectProperty.appendChild(objectPropertyTermVectors);
					ObjectProperty.appendChild(objectPropertyWebListShow);
					ObjectProperty.appendChild(objectPropertyWebDetailShow);
					ObjectProperty.appendChild(objectPropertyAdminListShow);
					ObjectProperty.appendChild(objectPropertyAdminDetailShow);
					ObjectProperty.appendChild(objectPropertySort);

					// 写入上级目录
					KnObjectProperty.appendChild(ObjectProperty);

				}
				// 写入上级目录
				KnData.appendChild(KnObjectProperty);

				List<Dict> dictList=publicService.getDict();
				Element KnDict = doc.createElement("KnDict");
				for (Dict dt : dictList) {
					//创建三级目录
					Element Dict = doc.createElement("Dict");
					// 二级标题属性
					Attr dictId = doc.createAttribute("id");
					// 赋值
					dictId.setNodeValue(dt.getId().toString());
					// 写入二级目录
					Dict.setAttributeNode(dictId);
					
					// 创建节点
					Element dictNameEn = doc.createElement("nameEn");
					// 赋值
					dictNameEn.setTextContent(dt.getNameEn());
					
					Element dictZameZh = doc.createElement("nameZh");
					dictZameZh.setTextContent(dt.getNameZh());
					
					Element dictType = doc.createElement("dictType");
					dictType.setTextContent(dt.getDictType().toString());
					
					Element dictsort = doc.createElement("sort");
					dictsort.setTextContent(dt.getSort().toString());
					
					// 将节点写入二级目录
					Dict.appendChild(dictNameEn);
					Dict.appendChild(dictZameZh);
					Dict.appendChild(dictType);
					Dict.appendChild(dictsort);
					// 写入上级目录
					KnDict.appendChild(Dict);
					
				}
				// 写入上级目录
				KnData.appendChild(KnDict);
				
				List<DictItem> dictItemList=publicService.getDictItem();
				Element KnDictItem = doc.createElement("KnDictItem");
				for (DictItem dl : dictItemList) {
					//Dict dict= publicService.findDict(dl.getDictId());
					//创建三级目录
					Element DictItem = doc.createElement("DictItem");
					// 二级标题属性
					Attr dictItemId = doc.createAttribute("id");
					// 赋值
					dictItemId.setNodeValue(dl.getId().toString());
					// 写入二级目录
					DictItem.setAttributeNode(dictItemId);
					Attr dictItemDictId = doc.createAttribute("dictNameEn");
					dictItemDictId.setNodeValue(publicService.findDict(dl.getDictId()).getNameEn());
					DictItem.setAttributeNode(dictItemDictId);
					
					Attr dictItemDictItemid = doc.createAttribute("dictItemNameEn");
					if(dl.getDictItemId() !=null && !"".equals(dl.getDictItemId()) && dl.getDictItemId() != 0){
							dictItemDictItemid.setNodeValue(publicService.findDictItem(dl.getDictItemId()).getNameEn());
					}
					DictItem.setAttributeNode(dictItemDictItemid);
					
					// 创建节点
					Element dictItemZameEn = doc.createElement("nameEn");
					// 赋值
					dictItemZameEn.setTextContent(dl.getNameEn());
					
					Element dictItemnameZh = doc.createElement("nameZh");
					dictItemnameZh.setTextContent(dl.getNameZh());
					
					Element value = doc.createElement("value");
					value.setTextContent(dl.getValue());
					
					Element dictItemsort = doc.createElement("sort");
					dictItemsort.setTextContent(dl.getSort().toString());
					
					// 将节点写入二级目录
					DictItem.appendChild(dictItemZameEn);
					DictItem.appendChild(dictItemnameZh);
					DictItem.appendChild(value);
					DictItem.appendChild(dictItemsort);
					// 写入上级目录
					KnDictItem.appendChild(DictItem);
					
				}
				// 写入上级目录
				KnData.appendChild(KnDictItem);
			}
			// 目录保存到doc
			doc.appendChild(KnData);

			// step9:获得一个TransformerFactory对象
			TransformerFactory transformerFactory = TransformerFactory
					.newInstance();
			// step10:获得一个Transformer对象
			Transformer transformer = transformerFactory.newTransformer();
			// step11:把document对象用一个DOMSource对象包装起来
			Source xmlSource = new DOMSource(doc);
			// 获取服务器地址
			ServletContext sc = request.getSession().getServletContext();
			String dir = sc.getRealPath("/XMLFile/");
			File dirFile = new File(dir);
			if (!dirFile.exists()) {
				dirFile.mkdirs();
			}

			String random = System.nanoTime() + ".xml";
			File downFile = new File(dirFile, random);
			Result outputTarget = new StreamResult(downFile);
			// step13:生成相应的xml文件
			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
			transformer.setOutputProperty(
					"{http://xml.apache.org/xslt}indent-amount", "4");
			transformer.transform(xmlSource, outputTarget);

			// 下载文件
			FileDownloadUtil.download(downFile, "知识结构管理.xml", request, response);

			} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
